【发布时间】:2021-11-16 06:00:59
【问题描述】:
我知道有些人会说这个问题是重复的,但我真的找不到有用的答案。
假设我有以下程序:
#include <iostream>
#include <string>
using std::cout;
int main(){
std::string something;
cout<<"Type something";
std::cin>>something;
}
如何使用setw() 使输出看起来像这样?
Type something "then after some whitespaces for example 10 the user will start typing"
我尝试在输出中使用setw():
#include <iostream>
#include <string>
#include <iomanip>
using std::cout;
int main(){
std::string something;
cout<<std::left<<std::setw(24)<<"Type something";
std::cin>>something;
}
预期的输出应该是:
实际输出为:
【问题讨论】:
-
在你的输出中使用
setw,而不是你的输入。 -
@NathanOliver 我尝试使用 cout
-
请向我们展示您的尝试。到目前为止,您显示的代码显示没有使用
setw。它甚至不包括iomanip。 -
@Chris 我编辑了你现在可以看到的代码
-
@Seba Can't reproduce,你展示的代码对我来说很好用。