关于c++中如何调整输出格式的讲解!!!

c++中的输出格式显然要比c中的简单的多了!!!呵呵!!
首先要在头文件中加入#include<iomanip>
然后就是setw(int n)要输出的字符串的长度,具体例子见下面!!!

#include<iostream>
#include<iomanip>
using namespace std;
int main()

 double a=123.456;
 int  b=789;
 cout<<right<<setw(10)<<a<<endl;//输出结果的前面有3个空格,因为123.456有7位,而且是右对齐的所以就在前面有3空格!!
 cout<<left<<setw(3)<<b<<endl;//输出结果正常!!!因为是左对齐的!哈!!!
return 0;
}

原文地址:https://www.cnblogs.com/xiohao/p/2789763.html