+ 2

Why is this code not getting the last word?

It's supposed to add each word in a string to a vector, but doesn't add the last word. Why? https://code.sololearn.com/cgGIhN5p0d55/?ref=app

21st Feb 2019, 5:29 AM
Daniel Cooper
Daniel Cooper - avatar
2 Respuestas
+ 3
It’s because the last word is stored in current, so after line 19, add: vect.push_back(current); And it will work.
21st Feb 2019, 5:36 AM
Rowsej
Rowsej - avatar
+ 2
Thanks Rowsej I tried modifying the if statement to see if i was equal to input.end() but that just gave me a compilation error. Not sure why I didn't think of your solution, lol.
21st Feb 2019, 3:08 PM
Daniel Cooper
Daniel Cooper - avatar