给定用户输入整数的 C++ 打印空格或制表符

编程入门 行业动态 更新时间:2024-10-07 19:18:38
本文介绍了给定用户输入整数的 C++ 打印空格或制表符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我需要将用户输入(一个数字)转换为 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屋!

更多推荐

[db:关键词]

本文发布于:2023-05-01 10:58:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1408609.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:制表符   整数   空格   用户

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!