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."

Recommended Answers

All 3 Replies

//while(!str_number.eof())
//     {
//     str_number >> str_description;
//     ...

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

Thanks!

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.