size_t start = 0, length;
string command = "get key", temp;
cout << "The command is: " << command << endl;
for( iter = command.begin(); *iter != ' '; ++iter )
temp = command.substr( start, length );
broken_up.push_back( temp );
start = length;
} while( iter != command.end() );
cout << "\nThe command has " << broken_up.size() << "words in it." << endl;
cout << "\nThe words in the command are:";
for ( vector<string>::iterator vec_iter = broken_up.begin();
vec_iter != broken_up.end();
cout << endl << *vec_iter;
The program produces no errors, but when it runs, it appears only for a brief second before terminating. I thought I had this solved with the cin.get() function (which has always worked for me in the past), but it doesn't change anything. I checked the 'Output' section of my compiler and it read thus:
Reading symbols from Broken_up2.exe...done.
Breakpoint 1 at )x401669: file (I don't want to type out the whole file name...), line 42.
Program exited with error...
Then it says 'frames-invalid' a bunch of times.
My questions: (a)what does 'frames-invalid' mean, and (b)how can I fix this program so I can see the result?
Oh, I see. Thanks. Is there any way to save a value so that I can set iter to the start of the next word (i.e. where the last one left off) each iteration? And I know I can't convert 'size_t's into 'iterator's, so do you have any suggestions?
I've been working a bit with that link and a few others and have concocted a program to save the tokens in a vector of strings, which seems to work all right (as far as I can tell), but when I try to display the tokens on the screen the program shuts down. Is there some infinite loop here again that I'm just missing?
You mean I want the null character rather than NULL? I don't think so.. I pretty much just copied off this site's example of how to use strtok, so I could be wrong. I don't quite understand strtok very well yet, or why I can't print it onto the screen with the 'while' statement.
Yeah, I guess I probably should use zero, but I've always thought NULL looks all important and caps-y and it adds a nice change of pace from all the lowercase letters I'm using. But whatever. Thanks for the help.