流操纵算子
整数流的基数:流草追踪算子dec,oct,hex
int n = 10;cout << n << endl;cout << hex << n << endl;cout << hex << n << endl;cout << dec << n << endl;cout << oct << n << endl;/* 输出结果10a1012*/
控制浮点精度的流操纵算子
非定点方式输出

-
定点方式输出
取消定点方式输出
设置域宽的流操纵算子


cin.width(5)包括最后一个‘\0‘在内,一共5个字符
#include <iostream>#include <iomanip>using namespace std;void main() {int n = 141;// 1) 分别以十六进制、十进制、八进制先后输出ncout << "1) " << hex << n << " " << dec << n << " " << oct << n << endl;double x = 1234567.89, y = 12.34567;// 2) 保留5位有效数字cout << "2) " << setprecision(5) << x << " " << y << " " << endl;// 3) 保留小数点后5位cout << "3) " << fixed << setprecision(5) << x << " " << y << endl;// 4) 科学计数法输出,且保留小数点后5位cout << "4) " << scientific << setprecision(5) << x << " " << y << endl;// 5) 非负数要小时正号,输出宽度的为12字符,宽度不足用'*'填充cout << "5) " << showpos << fixed << setw(12) << setfill('*') << 12.1 << endl;// 6) 非负数不显示正号,输出宽度为12字符,宽度不足则右边用填充字符填充cout << "6) " << noshowpos << setw(12) << left << 12.1 << endl;// 7) 输出宽度为12字符,宽度不足则左边用填充字符填充cout << "7) " << setw(12) << right << 12.1 << endl;// 8) 宽度不足时,负号和数值分列左右,中间用填充字符填充cout << "8) " << setw(12) << internal << -12.1 << endl;cout << "9) " << 12.1 << endl;}/* 输出1) 8d 141 2152) 1.2346e+006 12.3463) 1234567.89000 12.345674) 1.23457e+006 1.23457e+001 // 与2)输出不同,因为3)设置的fixed对4)也有效5) ***+12.10000 // 上面的setprecision()对下面的都有效6) 12.10000****7) ****12.100008) -***12.100009) 12.10000*/
用户自定义流操纵算子


会把cout作为参数交给函数
