关于cout输出中setw()的问题
有以下程序,setw()设置域宽和空格是什么关系?
#include <iostream>
#include <iomanip>
using namespace std;
void main()
{
int a=29,b=1001;
cout<<"123456789"<<endl;
cout<<a<<setw(6)<<b<<endl;
cout<<setw(6)<<a<<b<<endl;
}
输出结果如下:
123456789
29 1001
291001
设置了6个宽度,怎么第一排只有2个空格,第二行只有4个空格呢?不明白了。