Erasing using backspace control character

后端 未结 4 574
一个人的身影
一个人的身影 2020-12-02 19:09

I am trying to use the backspace control character \'\\b\' to erase trailing commas at the end of line. Although it works in cases where there is no other outpu

4条回答
  •  青春惊慌失措
    2020-12-02 19:49

    The usual way of erasing the last character on the console is to use the sequence "\b \b". This moves the cursor back one space, then writes a space to erase the character, and backspaces again so that new writes start at the old position. Note that \b by itself only moves the cursor.

    Of course, you could always avoid outputting the comma in the first place:

    if(i > 0) cout << ",";
    cout << a[i];
    

提交回复
热议问题