<3>C++ <1>在输入输出流中使用控制符

<3>C++ <1>在输入输出流中使用控制符_第1张图片

如以下代码:

#include  
#include 
using  namespace  std;
int  main()
{
	int x = 24;      double  y = 12.3456789;
	cout << dec << x << "    ";
	cout << hex << x << "    ";
	cout << oct << x << '\n';
	cout << dec;       
	cout << setw(8) << x << "," << x << endl;
	cout << setw(8) << setfill('*') << x << endl;
	cout << setprecision(5) << y << endl;
	return   0;
}

该代码对以上控制符都进行了展示。运行结果如下图:
<3>C++ <1>在输入输出流中使用控制符_第2张图片setw是设置数字对齐的最佳方式,并且可以附加setfill进行符号填充。

你可能感兴趣的:(<3>C++ <1>在输入输出流中使用控制符)