io代表输入输出,manip是manipulator(操纵器)的缩写-------来自于百度百科
具体函数:
1.setiosflags /*unspecified*/ setiosflags (ios_base::fmtflags mask);
setiosflags的参数是该流的格式标志值,这个值由如下位掩码(ios枚举器)指定,并可用位或OR(|)运算符进行组合:
ios::skipws 在输人中跳过空白。
ios::left 左对齐值,用填充字符填充右边。
ios::right 右对齐值;用填充字符填充左边(缺省对齐方式)。
ios::internal 在指定任何引导标记或基之后增加填充字符。
ios::dec 以基10(十进制)格式化数值(缺省进制)。
ios::oct 以基8(八进制)格式化数值。
ios::hex 以基16(十六进制)格式化数值。
ios::showbase 以C++编译器能读的格式显示数值常量。
ios::showpoint 对浮点数值显示小数点和尾部的0。
ios::uppercase 对于十六进制数值显示大写字母A到F,对于科学格式显示大写字母E。
ios::showpos 对于正数显示正号(+)。
ios::scientific 以科学格式显示浮点数值。
ios::fixed 以定点格式显示浮点数值。
ios::unitbuf 导致在每次插入之后ostream::osfx刷新该流。缺省地,cerr是缓冲的单元。
ios::stdio 导致在每次插入之后ostream::osfx刷新该流的stdout和stderr。
// setiosflags example
#include <iostream> // std::cout, std::hex, std::endl
#include <iomanip> // std::setiosflags
int main () {
std::cout << std::hex;
std::cout << std::setiosflags (std::ios::showbase | std::ios::uppercase);
std::cout << 100 << std::endl;
return 0;
}
Output:
0X64 |
2.resetiosflags:/*unspecified*/ resetiosflags (ios_base::fmtflags mask);
Behaves as if member unsetf were called with mask as argument on the stream on which it is inserted/extracted as a manipulator (it can be inserted/extracted on input streams or output streams).
|
|
This code first sets the showbase flag and then resets it using the resetiosflags manipulator. Output:
0x64 64 |
3.setbase:/*unspecified*/ setbase (int base);
Sets the basefield to one of its possible values: dec, hex or oct, according to argument base.
Behaves as if setf(which,ios_base::basefield)
were called on the stream on which it is inserted/extracted as a manipulator, with which being:
|
|
This code uses the setbase manipulator to set hexadecimal as the basefield selective flag.
Output:
6e |
/*unspecified*/ setfill (char_type c);
Behaves as if member fill were called with c as argument on the stream on which it is inserted as a manipulator (it can be inserted on output streams).
|
|
Output:
xxxxxxxx77 |
|
5.setprecision:设置有效数字用
/*unspecified*/ setprecision (int n);
Sets the decimal precision to be used to format floating-point values on output operations.
Behaves as if member precision were called with n as argument on the stream on which it is inserted/extracted as a manipulator (it can be inserted/extracted on input streams or output streams).
|
Output:
3.1416 3.14159 3.14159 3.141590000 |
6.setw设置域宽
/*undefined*/ setw (int n);
Behaves as if member width were called with n as argument on the stream on which it is inserted/extracted as a manipulator (it can be inserted/extracted on input streams or output streams).
|
Output:
77 |