This is my code:

stringstream str_number
         string description
     str_number >> str_description;
     if (str_description.length() < 1)
     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

//     {
//     str_number >> str_description;
//     ...

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


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, learning, and sharing knowledge.