I was just testing out the substr() method to parse a string's words into a string vector. I was just re-creating what I saw in the book I'm reading so I would understand it, but why I'm not getting the desired effect alludes me. I also tried it with a pre-defined string but still no go.
Here's the output
string temp = "";
string::size_type i, j;
cout << "Type a sentence." << endl;
i = 0;
while(i != aStr.size())
while(isspace(aStr[i]) && i != aStr.size())
j = i;
while(!isspace(aStr[j]) && j!= aStr.size())
temp = aStr.substr(i, j);
if (i != j)
i = j;
cout << "You typed " << parse.size() << " words:" << endl;
for (vector<string>::size_type i = 0; i < parse.size(); i++)
cout << parse[i] << endl;
Type a sentence.
The Quick Brown Fox Jumped Over The Fence!
You typed 8 words:
Brown Fox Jumpe
Fox Jumped Over The
Jumped Over The Fence!
Over The Fence!
Press any key to continue . . .