In my code there is a loop that adds sth like that “number,” to stringstream. When it ends, I need to extract ‘,’ add ‘}’ and add ‘{‘ if the loop is to repeated.
I thought i can use ignore() to remove ‘,’ but it didn’t work. Do you know how I can do what I describe?
example:
douCoh << '{';
for(unsigned int i=0;i<dataSize;i++)
if(v[i].test) douCoh << i+1 << ',';
douCoh.get(); douCoh << '}';
You can extract the string (with the
str()member), remove the last char withstd::string::eraseand then reset the new string as buffer to thestd::ostringstream.However, a better solution would be to not insert the superfluous
','in the first place, by doing something like that :