std :: cout打印N次字符 [英] std::cout to print character N times

查看:341
本文介绍了std :: cout打印N次字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用 std :: cout 打印N次字符而不循环?

How can I print a character N number of times using std::cout without looping?

是有一种方法可以将文本光标移回以使 std :: cout<<的效果无效。 std :: endl; ?即向上移动(例如,在执行 std :: cout<< std :: endl; 操作之后,我们从不打印任何内容)。

Is there a way to move the text cursor back to nullify the effect of std::cout << std::endl;? i.e. to move up a line (say we never printed anything after doing the std::cout << std::endl; operation).

推荐答案

 std::cout << std::string(100, '*') << std::endl;

要向上移动一行,必须诉诸终端逃生(假设 isatty()表示您正在运行一个。)

To move a line up, you have to resort to terminal escapes (assuming that isatty() indicates that you are running on one).

这篇关于std :: cout打印N次字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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