C++中 cout 按照不同的格式要求,来控制显示输出

此例介绍C++中 cout 按照不同的格式要求,来控制显示输出内容。

Code:

#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
	double n = 1.123456;
	cout << n << endl;
	cout << setprecision(3) << n << endl;
	cout << setiosflags(ios::fixed) << n << endl;
	cout << setiosflags(ios::fixed) << setprecision(7) << n << endl;
	return 0;
}


Display:



Davy_H

猜你喜欢

转载自blog.csdn.net/DavyHwang/article/details/7353669