Académique Documents
Professionnel Documents
Culture Documents
by…
kharadi fahad
c++ stream classes
IOS
get() put()
getline() write()
read() --------------
---------------- Overload ‘>>’
Overload ‘<<’
Types of i/o operation
I/O OPERATION
UNFORMATTED FORMATTED
width(int w) setw(int w)
precision(int d) setprecision(int d)
fill(char c) setfill(char c)
setf(arg1,arg2) setioflags(arg1,arg2)
unsetf() resetioflags()
3 6 1 1 8 3 6 1 1 8
2> precision(int d);-
Eg:-
cout.precision(4);
cout<<sqrt(2)<<‘\n’;
cout<<3.14159<<‘\n’;
cout<<2.50003<<‘\n’;
OUTPUT:-
1.4112TRUCATED VALUE.
3.1416ROUNDED TO NEAREST VALUE.
2.5 NO TRAILING ZEROS
• 3> fill(char c):-
Eg:-
cout.fill(‘ * ‘);
cout.width(10);
cout<<1265;
OUTPUT:-
* * * * * * 1 2 6 5
4>Formattingflags,Bit fields:-
setf(arg1,arg2):-
Format arg1 arg2
Left-justified o/p ios::left ios::adjustfield
Right-justified o/p ios::right ios:: adjustfield
Padding after base ios::internal ios:: adjustfield
or sign indicator
Scientific notation ios::scientific ios::floatfield
Fixed point notation ios::fixed ios:: floatfield
Decimal base ios::dec ios::basefield
Octal base ios::oct ios:: basefield
Hexadecimal base ios::hex ios:: basefield
Eg:-
cout.fill(‘*’);
cout.setf(ios::left,ios::adj
ustfield);
cout.width(12);
cout<<“oops”<<‘\n’;
OUTPUT:-
o o p s * * * * * * * *
• To display following
341.32 3 4 1 3 2
29.00 2 9
19.230 1 9 2 3
Other arg1 Description
setf(ios::showpoint) display a trailing decimal point and trailing
decimal zeros when real numbers are
displayed
setf(ios::showpos) display a + character with positive values.