I've been working on a program that is meant to take a full sentence from the user (saved as a vector<char>
) and divide it into words. It does this by using an iterator in a for
loop that looks something like this:
for ( *iter = sentence.begin(); *iter != ' '; iter++ )
words.push_back( *iter );
// Do some form of copying from
// the words vector to a string vector
(Assuming that sentence
is the vector<char>
is another vector<char>
. Also assuming that iter
is a normal iterator for a vector<char>
I need a way to fill in the line of code commented in the above block. The eventual outcome of the program is supposed to be the computer displaying each separate word in the sentence, so you can see that I need a way to put each word into a vector of its own. Then I can iterate through it and display each word.
My other problem is, how can I fill a vector<char>
up with a string from the user? For example, if the user input:
...how could I assign that to a vector<char>
so that the vector<char>
held the values
H, e, l, l, o, , w, o, r, l, d, .
to easily (maybe?) be copied over to a vector<string>
I hope this makes sense; if not, I'll be happy to try to clarify. Thanks.