#include #include using namespace std; int main() { float n1 = 1, n2 = 1.0, n3 = 1.1, n3a = 1.11, n4 = 1.19, n5 = 1.111, n6 = 1.119, n7 = 11, n8 = 111; cout << "Definitions are 1 1.0 1.1 1.11 1.19 1.111 1.119 11 111" << endl; cout << endl; cout << "Defaults:" << endl; cout << n1 << " " << n2 << " " << n3 << " " << n3a << " " << n4 << " " << n5 << " " << n6 << " " << n7 << " " << n8 << endl; cout << endl; cout << "Default setprecision(6) shouldn't change anything:" << endl; cout << setprecision(6); cout << n1 << " " << n2 << " " << n3 << " " << n3a << " " << n4 << " " << n5 << " " << n6 << " " << n7 << " " << n8 << endl; cout << endl; cout << "From here on use setprecision(2):" << endl; cout << setprecision(2); cout << n1 << " " << n2 << " " << n3 << " " << n3a << " " << n4 << " " << n5 << " " << n6 << " " << n7 << " " << n8 << endl; cout << endl; cout << "Return to default of setprecision(6):" << endl; cout << setprecision(6); cout << n1 << " " << n2 << " " << n3 << " " << n3a << " " << n4 << " " << n5 << " " << n6 << " " << n7 << " " << n8 << endl; cout << endl; cout << "Fixed:" << endl; cout << setiosflags(ios::fixed); cout << n1 << " " << n2 << " " << n3 << " " << n3a << " " << n4 << " " << n5 << " " << n6 << " " << n7 << " " << n8 << endl; cout << endl; cout << "Reset fixed:" << endl; cout << resetiosflags(ios::fixed); cout << n1 << " " << n2 << " " << n3 << " " << n3a << " " << n4 << " " << n5 << " " << n6 << " " << n7 << " " << n8 << endl; cout << endl; /* Definitions are 1 1.0 1.1 1.11 1.19 1.111 1.119 11 111 Defaults: 1 1 1.1 1.11 1.19 1.111 1.119 11 111 Default setprecision(6) shouldn't change anything: 1 1 1.1 1.11 1.19 1.111 1.119 11 111 From here on use setprecision(2): 1 1 1.1 1.1 1.2 1.1 1.1 11 1.1e+02 Return to default of setprecision(6): 1 1 1.1 1.11 1.19 1.111 1.119 11 111 Fixed: 1.000000 1.000000 1.100000 1.110000 1.190000 1.111000 1.119000 11.000000 111.000000 Reset fixed: 1 1 1.1 1.11 1.19 1.111 1.119 11 111 */ return 0; }