Say the input has two lines, both of which are "Hello world". This is the output:
Hello: 6
world
Hello: 11
world: 5
1 2 3 4 5 6 7 8 9
while (getline(cin, line, ' ')) { //space is the delimiter
token = line.substr(0, line.find(' ')); //token now has the word separated by space
count = token.length();
cout << token << ":" << count << endl;
//erase the part of string that is already tokenized
line.erase(0, token.length());
}
}
So apparently the last word of the first line isn't getting read, but is being read in the next line. I'm deleting the word that we already tokenized at the end, so that when we substring it, it would always start at 0. Any advice would be nice.