c++ 回车行 长字符串后跟较短的字符串

c++ Carriage Return Line Feed long string followed by a shorter string

本文关键字:字符串 c++ 回车      更新时间:2023-10-16

>我有一个应用程序,我想用它来打印状态消息。但是,有时会出现较短的状态消息跟在较长的状态消息之后的情况,这会导致以下情况:

长消息:

this is the long status message which is longer than the short one

较短的消息:

This is the short status messagewhich is longer than the short one
//this one should end here      ^

我使用的代码是:

cout << StatusMessage << 'r';

如何克服这个问题,并在打印新行之前先擦除整行?最好是跨平台解决方案,但现在我正在研究 Windows

注意:我已经尝试用bspaces覆盖该行,但是这可能会导致多行清理,从而删除我的r方法的功能。

我会在前一个输出的长度中反复使用'b'(退格键(。它似乎非常标准化:

cout << StatusMessage << 'r';
cout << std::string(StatusMessage.size(),'b');