remove char from stringstream and append some data

后端 未结 9 1529
情深已故
情深已故 2020-12-31 01:42

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.

9条回答
  •  余生分开走
    2020-12-31 01:59

    I have had this very problem and I found out that you can simply do:

    douCoh.seekp(-1, std::ios_base::end);
    

    And the keep inserting data. As others stated, avoiding inserting the bad data in the first place is probably the ideal solution, but in my case was the result of a 3rd party library function, and also I wanted to avoid copying the data to strings.

提交回复
热议问题