回退std :: cout回到一行的开头 [英] Rewinding std::cout to go back to the beginning of a line

查看:686
本文介绍了回退std :: cout回到一行的开头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Mac OS X编写一个用于处理一系列文件的命令行工具。我想向用户显示正在处理的当前文件,但不想要一个bazillion文件污染终端窗口。

I'm writing a command-line tool for Mac OS X that processes a bunch of files. I would like to show the user the current file being processed, but do not want a bazillion files polluting the terminal window.

而是我想使用一行输出文件路径,然后重用该行为下一个文件。是否有一个字符(或一些其他代码)输出到 std :: cout 来完成这个?

Instead I would like to use a single line to output the file path, then reuse that line for the next file. Is there a character (or some other code) to output to std::cout to accomplish this?

此外,如果我想为Windows重新定位此工具,两个平台的解决方案是否相同?

Also, if I wanted to re-target this tool for Windows, would the solution be the same for both platforms?

推荐答案

\r应该适用于Windows和Mac OS X。

"\r" should work for both windows and Mac OS X.

>

Something like:

std::cout << "will not see this\rwill see this" << std::flush;
std::cout << std::endl; // all done

这篇关于回退std :: cout回到一行的开头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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