c++ 在同一行打印

标签 c++ printing cout

我正在使用 chrono 来获取循环中耗时。我想在每次循环运行时显示这个时间。

我能做到:

for(int i = 0;i<3;i++)
{
    sleep(2 secs);
    time= get_time();
    cout<<"time is : "<<time;
}

但我有输出:

time is : 2 time is : 4 time is : 6

我可以添加一个 endl 以将其放在列中,但这不是我想要的。我的循环大约一百万次,所以我真的不想打印一百万行。

我只想像这样打印:

time is : 2

然后刷新为

time is : 4

等等。有办法做到这一点吗?

最佳答案

您可以将 endl 与 clrscr() 一起使用。

关于c++ 在同一行打印,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43330363/

相关文章:

asp.net - ASP :multiview control - can we show all the views on one tab instead of different tabs

c++ - vector 的最后一项不显示/vector 索引问题

C++ 套接字、多线程和输出处理

c++ - Vulkan 中的 YCbCr 采样器

c++ - 为什么我得到 "No viable conversion from ' vector<Country >' to ' int'"?

c++ - ProgressBar 在没有调试器的情况下运行时获取 'stuck'

java - 我的打印机不支持 postscript?

java pdf 打印 NetBeans

为 cout 取消引用指针时的 C++ SegFault

c++ - 如何在不改变元素顺序的情况下合并两个unordered_map?