Make an array of words from a sentence?
-
Hi, First off I am new to VC++, so this is probably real basic stuff but I keep getting an error. What I have so far : // now all items are in list, so step through list to print them. list::iterator itr; for (itr = parsed_items.begin(); itr != parsed_items.end(); ++itr ) { int count = 0; string dmp = *itr; cstr = dmp.c_str(); // convert string to CString plb->AddString( cstr ); // print to List Box LPCTSTR word = cstr; // How do I add the variable word into an array each time the loop goes round // I want to end being able to access all the words in a sentence i.e. // word[0] // word[1] // word[2] // etc... count++; } The comments in my code explain what I am trying to achieve. Any help will be greatly appreciated, as I have been working on this and looking at various examples for two days now and am about to pull my hair out. Thanks in advance :-) Tryhard :-) :confused: :confused: Tryhard :-)
-
Hi, First off I am new to VC++, so this is probably real basic stuff but I keep getting an error. What I have so far : // now all items are in list, so step through list to print them. list::iterator itr; for (itr = parsed_items.begin(); itr != parsed_items.end(); ++itr ) { int count = 0; string dmp = *itr; cstr = dmp.c_str(); // convert string to CString plb->AddString( cstr ); // print to List Box LPCTSTR word = cstr; // How do I add the variable word into an array each time the loop goes round // I want to end being able to access all the words in a sentence i.e. // word[0] // word[1] // word[2] // etc... count++; } The comments in my code explain what I am trying to achieve. Any help will be greatly appreciated, as I have been working on this and looking at various examples for two days now and am about to pull my hair out. Thanks in advance :-) Tryhard :-) :confused: :confused: Tryhard :-)
This compiles ? Surely you need List::iterator ? Forget I said that, I'm sure you typed List<string>::iterator and lost the template argument as a bad tag as I did..... Also, why convert string to CString ? Why not start with whichever string class you want and stay there ? Either way, I don't know for sure if CString has an equivelant, or even if STL does ( shame on me ), but strtok will do what you want with a basic char*. Christian As I learn the innermost secrets of the around me, they reward me in many ways to keep quiet. Men with pierced ears are better prepared for marriage. They've experienced pain and bought Jewellery.