Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Console writing, delete characters

My question concerns deleting already written chars in the console. Is there a way to do it? Lets say i write 10 spaces to the console. Can i delete some to make space for other chars without the output exeeding 10 chars? I use a special libary given, with functions for writing in the console etc.

like image 395
Bartlomiej Lewandowski Avatar asked Feb 03 '26 03:02

Bartlomiej Lewandowski


2 Answers

Use '\b'. It erases one character, and the cursor moves back:

std::cout << "nawaz"; //screen shows : nawaz
std::cout << '\b'; //'z' is erased, now screen shows : nawa
like image 174
Nawaz Avatar answered Feb 04 '26 15:02

Nawaz


do {

cout<<"\b"<<num--;

}

while ( num >0 ); 
like image 39
Alon Adler Avatar answered Feb 04 '26 16:02

Alon Adler



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!