#include
io代表输入输出,manip是manipulator(操纵器)的缩写(在c++上只能通过输入缩写才有效。)
iomanip的作用:
主要是对cin,cout之类的一些流操纵运算。以下是一些常见的控制函数的:
dec 置基数为10 相当于"%d"
hex 置基数为16 相当于"%X"
oct 置基数为8 相当于"%o"
setfill( ‘c’ ) 设填充字符为c
setprecision( n ) 设显示小数精度为n位
setw( n ) 设域宽为n个字符
示例: int test[4] = { 1,22,23,143 };
for (int i = 0; i < 4; i++)
{
cout << setw(4) << setfill(‘0’) << test[i] << ‘\n’;
}
运行结果:
0001
0022
0023
0143