c ++回车换行送入长string后跟一个较短的string

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

长信息:

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'; 

我怎样才能克服这个问题,并在印刷新行之前首先抹掉整条生产线? 最好有一个跨平台的解决scheme,但现在我在Windows上工作

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

我会重复使用'\b' (backspace)在前一个输出的长度为您的情况。 它似乎相当标准化 :

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