| | |
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 25 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: 629
Reputation:
Solved Threads: 46
0
#4 25 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: My Sample C++ Code
- Next Thread: how to display this using for loop??
| Thread Tools | Search this Thread |
api array beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets





