C++设置输出域宽与设置标志

 

使用set iOS flags(ios_base::right); 设置标志

通过resetiosflags(ios_base::right);  清楚设置标志,只有清楚设置标志之后才能重新设置

#include 
#include

using namespace std;

void main()
{
	cout << setfill('*')
		<< setw(0) << 15 << endl
		<< setw(1) << 15 << endl
		<< setw(2) << 15 << endl
		<< setw(3) << 15 << endl
		<< setw(4) << 15 << endl;
	cout << setw(16) << setfill('*') << "" << endl;
	cout << setiosflags(ios_base::right)    //按输出域右边对齐输出
		<< setw(5) << 1
		<< setw(5) << 2
		<< setw(5) << 3 << endl;
	cout << resetiosflags(ios_base::right);
	cout << setiosflags(ios_base::left)        //按输出域左边边对齐输出
		<< setw(5) << 1
		<< setw(5) << 2
		<< setw(5) << 3 << endl;
}

显示结果

C++设置输出域宽与设置标志_第1张图片

你可能感兴趣的:(总结)