設定有效數字
const double PI = 3.141592653;
cout << setprecision(10) << PI << endl;           //3.141592653十位有效位數
cout << setprecision(8) << PI << endl;           //3.1415927八位有效位數
cout << setprecision(6) << PI << endl;           //3.14159六位有效位數
setw(),setprecision()練習:
#include <iostream>
#include <iomanip>
using namespace std;
const double PI = 3.141592653;
 
int main(int argc, char** argv)
{
    cout << setprecision(8);
	cout << setw(10) << PI * -1 << endl; 
	cout << setw(10) << PI * 100 << endl; 
	cout << setw(10) << PI * 10000 << endl; 
	system("PAUSE");
	return 0;
}
輸出結果:
設定輸出旗號
setiosflags(),setprecision()練習:
#include <iostream>
#include <iomanip>
using namespace std;
const double PI = 3.141592653;
 
int main(int argc, char** argv)
{
    cout << setprecision(8)
         << setiosflags(ios::fixed);
	cout << setw(10) << PI * -1 << endl; 
	cout << setw(10) << PI * 100 << endl; 
	cout << setw(10) << PI * 10000 << endl; 
	system("PAUSE");
	return 0;
}
輸出結果: