// ex2_2cppThe output from this is below, with one or two extra line spaces removed for clarity.
#include "stdafx.h"
#include <iostream>
using namespace std;
int main(int argc, char* argv[])
{
cout.width(10) ;
cout << right << "Test" << endl;
cout << left << "Test 2" << endl;
cout << internal <<"Test 3" << endl;
cout << endl;
cout.precision(2) ;
cout << 45.678 << endl;
cout << uppercase << "David" << endl;
cout.precision(8) ;
cout << scientific << endl;
cout << 450678762345.123 << endl;
cout << fixed << endl;
cout << 450678762345.123 << endl;
cout << showbase << endl;
cout << showpos << endl;
cout << hex << endl;
cout << 1234 << endl;
cout << oct << endl;
cout << 1234 << endl;
cout << dec << endl;
cout << 1234 << endl;
cout << noshowbase << endl;
cout << noshowpos << endl;
cout.unsetf(ios::uppercase) ;
cout << hex << endl;
cout << 1234 << endl;
cout << oct << endl;
cout << 1234 << endl;
cout << dec << endl;
cout << 1234 << endl;
return 0;
}
TestNote: Despite the uppercase, David is printed as David and not DAVID. This is because uppercase only affects generated output- e.g. numbers printed in hexadecimal. So the hex output 4d2 is 4D2 when uppercase is in operation.
Test 2
Test 3
46
David
4.50678762E+011
450678762345.12299000
0X4D2
02322
+1234
4d2
2322
1234
Also, most of these manipulators actually set a bit in a flag and it is possible to set this directly with
cout.setf()and clear it with
cout.unsetf()
On the next page : More About setf And unsetf()

