เอาต์พุตสตรีม cout อนุญาตให้ใช้ตัวจัดการที่คุณสามารถใช้เพื่อตั้งค่าความแม่นยำโดยตรงบน cout และใช้ตัวระบุรูปแบบคงที่ เพื่อให้ได้ความแม่นยำของสองเท่า คุณสามารถใช้ไลบรารีขีดจำกัด ตัวอย่างเช่น
ตัวอย่าง
#include<iostream>
#include <limits>
using namespace std;
int main() {
// Get numeric limits of double
typedef std::numeric_limits< double > dbl;
double PI = 3.14159265358979;
cout.precision(dbl::max_digits10);
cout << "Pi: " << fixed << PI << endl;
return 0;
} ผลลัพธ์
สิ่งนี้จะให้ผลลัพธ์ -
3.14159265358979