C++ setw()在我的代码上工作不正常
我的代码有问题,不确定是错误还是代码有问题C++ setw()在我的代码上工作不正常,c++,C++,我的代码有问题,不确定是错误还是代码有问题 #include <iostream> #include <iomanip> using namespace std; int main() { cout << setfill('*') << setw(80) << "*"; cout << setw(21) << "Mt.Pleasant Official Billing Statement" <<
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
cout << setfill('*') << setw(80) << "*";
cout << setw(21) << "Mt.Pleasant Official Billing Statement" << endl;
cout << setfill('*') << setw(80) << "*" << endl;
return 0;
}
#包括
#包括
使用名称空间std;
int main()
{
cout不移动文本,但设置文本的最小宽度
为了实现您的想法,您应该尝试使用更大的值,因为您的字符串长度超过21个字符,例如
cout << setfill('*') << setw(80) << "*" << endl;
cout << setfill(' ') << setw(56) << "Mt.Pleasant Official Billing Statement" << endl;
cout << setfill('*') << setw(80) << "*" << endl;
如果你特别想要21个额外的空间或者什么的,把它们放进去。
********************************************************************************
Mt.Pleasant Official Billing Statement
********************************************************************************