setw()称为操纵程序(manipulator),它允许操纵或控制输出的外观。操纵程序不输出任何内容,只是修改输出过程。它的作用是把下一个要输出的值的字段宽度设置为括号中指定的字符数,使用setw()设置的字段宽度只应用于下一个写入cout的值。后续的值会以默认格式显示。setw()包含在<iomanip>头文件里,小示例如下:
#include <iostream>
#include <iomanip>
using std::cout;
using std::endl;
using std::setw;
int main(void){
cout<< setw(10)<<10+20 <<endl;
cout<< setw(10)<<10-5 <<endl;
cout<< setw(10)<<10-20 <<endl;
cout<< setw(10)<<10/3 <<endl;
return 0;
}
原文:http://blog.csdn.net/u010142437/article/details/29589683