c++ - How can I delete characters in stdout by programming? -
i want emulate backspace in programming , implemented 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 result 
how can result below without need of replacing tails blank space
123 that how can delete, rather replace, character after cursor has been backspaced.
use "clear end of line" escape sequence, csi k.
cout << "123456"; cout << "\b\b\b\033[k"; cout << endl; for list of escape sequences, see ansi escape code (wikipedia). of course, not of them work on terminals, these days, software terminals, wouldn't worry it.
Comments
Post a Comment