给定用户输入整数的 C++ 打印空格或制表符 [英] C++ printing spaces or tabs given a user input integer

查看:25
本文介绍了给定用户输入整数的 C++ 打印空格或制表符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将用户输入(一个数字)转换为 TAB 空格的输出.我问用户的例子:

I need to turn user input (a number) into an output of TAB spaces. Example I ask user:

cout << "Enter amount of spaces you would like (integer)" << endl;
cin >> n;

(n) 我需要把它变成像这样的输出:

the (n) i need to turn it into an output like:

cout << n , endl; 

屏幕上打印的是空格前任输入是 5输出|_|<~~~那里有五个空格.

and what prints on the screen would be the spaces ex input is 5 out put |_| <~~~there are five spaces there.

抱歉,如果我不清楚,可能这就是我无法通过其他人的问题找到答案的原因.

Sorry If I can't be clear, probably this is the reason I haven't been able to find an answer looking through other people's questions.

将不胜感激任何帮助.

推荐答案

cout << "Enter amount of spaces you would like (integer)" << endl; 
cin >> n;
//print n spaces
for (int i = 0; i < n; ++i)
{
   cout << " " ;
}
cout <<endl;

这篇关于给定用户输入整数的 C++ 打印空格或制表符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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