//====================== //f02089.cpp //流状态 //===================== #include<iostream> #include<iomanip> using namespace std; //--------------------- int main() { cout << showpos << 12 <<endl; //showpos:0和正数前显示+ cout << hex << 18 << " " << showbase << 18 <<endl; //hex十六进制显示整数,showbase:十六制前加OX,八进制前加:O cout << oct << 9 <<endl;//oct:八进制显示整数,dec:十进制显示整数 cout << hex << 255 << " " << uppercase << 255 <<endl;//uppercase:十六进制格式字母用大写字母表示(默认为小写) cout << 123.0 << " " << showpoint << 123.0 <<endl;//showpoint:浮点数输出即使小数点后为0也输出小数点 cout << (2 > 3) << " " <<boolalpha<<(2<3)<<endl; //boolalpha:逻辑值1/0,用ture/false表示 cout << fixed << 12345.678 <<endl;//fixed:定点数格式输出 cout << scientific << 12345.678 <<endl;//scientific:科学记数法输出 cout.unsetf(ios::scientific);//cout捆绑函数调用来取消显示格式 cout.unsetf(ios::showpos); cout << 12345.678 <<endl; cout << showpos << 12345.678 <<endl; cout << noshowpos << 12345.678 <<endl;//取消流状态:noshowpos,noshowbase,nouppercase,noshowpoint,noboolalpha cout.unsetf(ios::hex); cout.width(5);//设置显示宽度 cout.fill('*');//设置填充字符 cout << 123 << 23 <<endl;//width(n)为一次性操作 cout.width(5); cout.fill('$'); cout << left << 23 << endl;//left:左对齐,填充字符在右边,默认在左边 cout.precision(7); //precision:设置有效位数(总位数,普通显示方式)或精度(小数点后的位数,定点或科学记数法) cout << 1234.5 <<endl; cout << fixed << 1234.5 <<endl; cout << scientific << 1234.5 <<endl; cout.unsetf(ios::scientific); cout.precision(6); //默认输出有效位数为6位 cout << 1234.5 <<endl; cout << right << setw(5) <<setfill('*') << 23 <<endl;//setw(int),设置宽度,setfill(char):设置填充字符 cout << setprecision(7) <<1234.5 <<endl; cout.precision(6); cout << 1234.5 <<endl; return 0; } //=====================