remove char from stringstream and append some data

后端 未结 9 1498
情深已故
情深已故 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 02:05

    You can seek the stringstream and go back 1 character, using stringstream::seekp. Note that it does not remove the last character, but only moves the write head. This is sufficient in this case, as we overwrite the last character with an }.

    douCoh << '{';
    for(unsigned int i=0;i

提交回复
热议问题