I want to emulate backspace in programming and implemented as below.
// del.cpp
#include <iostream>
using namespace std;
int main()
{
cout << "123456";
cout << "\b\b\b" /* backspace key */<< '\x7f' /* DEL key */ << '\x7f' << '\x7f';
cout << endl;
return 0;
}
But I get a result like this

How can I get a result just like below without the need of replacing the tails with blank space
123
That is to say how can I delete, rather than replace, those character after the cursor which has been backspaced.
Use the “clear to end of line” escape sequence,
CSI K.For a list of escape sequences, see ANSI Escape Code (Wikipedia). Of course, not all of them will work on all terminals, but these days, with software terminals, I wouldn’t worry about it.