| | |
Removing stl features from a program
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2009
Posts: 8
Reputation:
Solved Threads: 0
Hi guys, anyone familiar with the Markov Chain Algorithm? I've got an assignment to take the code from a C++ implementation and remove any stl features like deques and maps, but continue to use strings as my main object type. I've based my changes around a C version of the code, which really just needs to be adapted to use C++ strings instead of C char arrays.
The place I'm running into trouble is trying to initialize all my strings with the "non-word" value . Here's the relevant code:
The error I get when I go to compile the code is
"prob3.cpp:104: error: invalid conversion from `const char' to `std::string*'"
pointing to the body of the for loop in main intended to put "\n" in each field of prefix. I've tried replacing all references to NONWORD with but I get the same error. Does anyone have a tip to caste or convert newline as a string?
I have a feeling this is just one of several little hurdles, so if anyone wants to see more of my code to try and find a way around this problem, let me know.
The place I'm running into trouble is trying to initialize all my strings with the "non-word" value
C++ Syntax (Toggle Plain Text)
"\n"
C++ Syntax (Toggle Plain Text)
... const char NONWORD[] = "\n"; ... int main(void) { int i, nwords = MAXGEN; string *prefix[NPREF]; // current input prefix srand(time(NULL)); for (int i = 0; i < NPREF; i++) hashadd(prefix, NONWORD); hashbuild(prefix, cin); hashadd(prefix, NONWORD); hashgenerate(nwords); return 0; } ... void hashadd(string *prefix[NPREF], string *suffix) { State *sp; sp = lookup(prefix, 1); addsuffix(sp, suffix); memmove(prefix, prefix+1, (NPREF-1)*sizeof(prefix[0])); prefix[NPREF - 1] = suffix; }
"prob3.cpp:104: error: invalid conversion from `const char' to `std::string*'"
pointing to the body of the for loop in main intended to put "\n" in each field of prefix. I've tried replacing all references to NONWORD with
C++ Syntax (Toggle Plain Text)
"\n"
I have a feeling this is just one of several little hurdles, so if anyone wants to see more of my code to try and find a way around this problem, let me know.
•
•
Join Date: Oct 2009
Posts: 8
Reputation:
Solved Threads: 0
0
#3 34 Days Ago
It's a homework assignment to prove why it's so useful to have the stl features, while at the same time testing your abilities. Unfortunately, being a transfer student at my school puts you at a disadvantage during some of these more arcane assignments.
•
•
Join Date: Feb 2008
Posts: 634
Reputation:
Solved Threads: 46
0
#4 34 Days Ago
Is this what you are looking for?
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <string> int main() { const char NONWORD[] = "\n"; std::string test = NONWORD; return 0; }
![]() |
Similar Threads
- Square root program without sqrt or pwr (C++)
- removing icons from task bar (Windows NT / 2000 / XP)
- Debugging with STL vectors (C++)
- Anyone program an image viewer for me? (Software Development Job Offers)
- Trouble With STL Lists (C++)
- _posix_thread_process_shared (C)
- Removing Bridge.dll (Web Browsers)
- 3d Program (Game Development)
Other Threads in the C++ Forum
- Previous Thread: program writen to transfer galons into liters per mile
- Next Thread: how to display this using for loop??
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy directshow dll download dynamic dynamiccharacterarray email encryption error file format forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib library linkedlist linker list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings studio temperature template test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets





