C++ c++;回车线进纸长字符串后跟短字符串

C++ c++;回车线进纸长字符串后跟短字符串,c++,windows,console-application,carriage-return,C++,Windows,Console Application,Carriage Return,我有一个要打印状态消息的应用程序。但是,有时会出现较短的状态消息跟随较长的状态消息的情况,这会导致以下情况: 长消息: 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 &

我有一个要打印状态消息的应用程序。但是,有时会出现较短的状态消息跟随较长的状态消息的情况,这会导致以下情况:

长消息:

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';
cout对于您的案例,我会在前一个输出的长度中重复使用
'\b'
(退格)。看起来很美:


请用示例代码及其输出澄清一下,当您尝试使用spacesC++时,您的问题是什么?它没有任何控制台的概念。如果你需要便携性,我会寻找一个控制台库。如果我在彼此后面这样做,它会给我打印一个空行,对吗?@TVAvanHesteren它会返回到当前行的开头(我甚至不确定
'\r'
是否真的是你想要的)。我用
cout替换了你的第二行
cout << StatusMessage << '\r';
cout << std::string(StatusMessage.size(),'\b');