📄 demo_2_io_format_1_b.cpp
字号:
//***************************************************
// 用流对象的成员函数进行格式化输出
//***************************************************
# include <iostream.h>
int main()
{
double a=123,b=123.456;
cout<<a<<endl;
cout<<b<<endl;
cout.setf(ios::showpos|ios::scientific);
cout<<a<<endl;
cout<<b<<endl;
cout.unsetf(ios::showpos|ios::scientific);
cout.fill('*');
cout.setf(ios::left);
cout.width(10); //设置后仅对下一个输出数据一次性有效
cout<<a<<endl;
cout.width(10);
cout<<b<<endl;
cout.unsetf(ios::left);
cout.precision(5);
cout<<a<<endl;
cout<<b<<endl;
return 0;
}
/*
123
123.456
+1.230000e+002
+1.234560e+002
123*******
123.456***
123
123.46
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -