// $PUB/p2-8.cpp : A demonstration of output manipulators. #include #include using namespace std; int main() { float fa = 1.; float fb = 9.874; float fc = 9874567.875; double fd = 9874567.875; cout << "Demonstrate output manipulators" << endl << endl; cout << fa << " " << fb << " " << fc << " " << fd; cout << "\t\t\tWith no manipulators\n\n"; cout << showpoint; cout << fa << " " << fb << " " << fc << " " << fd; cout << "\t\tWith showpoint added\n\n"; cout << fixed; cout << fa << " " << fb << " " << fc << " " << fd; cout << "\tWith fixed added\n\n"; cout << setprecision(0); cout << fa << " " << fb << " " << fc << " " << fd; cout << "\t\tWith setprecision(0) added\n\n"; cout << setprecision(2); cout << fa << " " << fb << " " << fc << " " << fd; cout << "\tWith setprecision(2) added\n\n"; cout << scientific; cout << fa << " " << fb << " " << fc << " " << fd; cout << "\t\tBack to scientific format\n\n"; return 0; } // main /* Results: Demonstrate output manipulators 1 9.874 9.87457e+06 9.87457e+06 With no manipulators 1.00000 9.87400 9.87457e+06 9.87457e+06 With showpoint added 1.000000 9.874000 9874568.000000 9874567.875000 With fixed added 1. 10. 9874568. 9874568. With setprecision(0) added 1.00 9.87 9874568.00 9874567.88 With setprecision(2) added 1.00e+00 9.87e+00 9.87e+06 9.87e+06 Back to scientific format */