0

This is my code:

stringstream str_number
         string description
while(!str_number.eof())
     {
     str_number >> str_description;
     if (str_description.length() < 1)
       {
       break;
       }
     description = description +" "+ str_description;
     }

My problem is that if the description is more than one string, the last string is repeated twice. For example if the description is: "Hello World," then the final description becomes: "Hello World World."

3
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by nuclear
0
//while(!str_number.eof())
//     {
//     str_number >> str_description;
//     ...

while( str_number >> str_description ) // while attempt to extract a string has succeeded 
     {
       ...

Edited by vijayan121: n/a

0

Not sure if i understood correctly but perhaps instead of line:

str_number >> str_description;

you should add:

getline(str_number, str_description);

This will save the whole line into str_description.

Edited by nuclear: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.