I have used a method called istringstream to split the string input into word segements.And it was successful.
But the problem is it displays the end word segment(last word of the last line) repetitively another two times.
eg: if the input is: Hello world this is my first c++ program.
result is:
1 2 3 4 5 6 7 8 9 10 11 12
hello
world
this
is
my
first
c++
program.
program.
program.
Note that the spaces(newlines) in line 10 and 11 are generated from the program.
can anyone give me a solution to eliminate those repetitive last word segments.
Thanks a lot. It works. I have just understood the mistake i have done that the while loop runs one more time until condition becomes false. Its very clear in your reply and helps me a lot.