开发者

Console writing, delete characters

开发者 https://www.devze.com 2023-04-11 01:18 出处:网络
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

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.


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


do {

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

}

while ( num >0 ); 


Depends on the type of terminal you're using, you could use the escape codes to control it.

For Windows, there are also API functions, if I remember correctly.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号