C ++改变控制台上的输出 [英] C++ changing output on console

查看:139
本文介绍了C ++改变控制台上的输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在控制台中显示更改号码的最简单方法是什么?我有一个正常的C ++命令行程序使用 cout ,但我想显示一个百分比数字代表进度,计数到100,而不打印新行。如何做? (如果重要的话:我在Windows 7上)
感谢您的回答!

What is the easiest way to display changing numbers in the console? I have a normal commandline program in C++ which uses cout, but I'd like to display a percentage number representing the progress which counts up to 100 without printing a new line. How is that done? (If it matters: I'm on Windows 7) Thanks for your answers!

推荐答案

When I&rsquo需要我在C ++ \r 中输出回车字符。

When I’ve needed that I have just output a carriage return character, in C++ \r.

记住每次刷新输出,例如

cout << "\r" << x << "% completed.       " << flush;

结尾的空格清除行上的上一个输出

The spaces at the end to clear previous output on the line in case of Microsoft-like fluctuating progress.

这篇关于C ++改变控制台上的输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆