如何在控制台项目中重写一行文本?C ++ [英] How do I rewrite a line of text in a console project? c++
问题描述
我正在研究c ++控制台项目,我想显示一个百分比而不每次都换行(以免窗口被成千上万的行阻塞).
I'm working on a c++ console project and i would like to show a percentage without making a new line each time (so that the window doesn't get clogged with thousands of lines).
是否可以删除最后打印的一行,或者说我下次输出一行时应该替换当前行?
Is there a way of removing the last line that was printed or something to say that the next time that i output a line it should replace the current line?
推荐答案
您可以使用\ r(回车)将光标返回到行首:
You can use a \r (carriage return) to return the cursor to the beginning of the line:
这适用于Windows和Linux.
This works on windows and Linux.
You could alternatively use a series of backspaces.
string str="Hello!";
cout << str;
cout << string(str.length(),'\b');
cout << "Hello again!";
来自: http://www.cplusplus.com/forum/unices/25744/
也许标记为重复的?我真的不确定如何.
Maybe mark as duplicate? I am really not sure how.
这篇关于如何在控制台项目中重写一行文本?C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!