Unit7
Unit7
Managing Console
I/O Operations
I/O and File Management
Concept of streams
cin and cout objects
C++ stream classes
Unformatted and formatted I/O
Manipulators
File stream
C++ File stream classes
File management functions
File modes
Binary and random Files
Concepts of Streams
Concept of Streams
Program Program
Input
Input stream
device
Program
Output stream
Output
device
Stream class for console I/O operations
General input/output
input stream ios stream class
class
pointer
output stream class
istream streambuf ostream
input output
fill() To specify a character that is used to fill the unused portion of a field.
setf() To specify format flags that can control the form of output.
unsetf() To clear the flags specified
Example: output:
output:
cout.precision(6
cout.fill('*');
cout.width(6); * * * 5 42 3. 6 4 5 7 5
cout.setf(ios::left,ios::adjustfield)
);
cout.width(6);
cout<<"543";
;
cout.width(10);
cout<<"543"; output:
cout.width(6);
cout<<sqrt(7); 5 4 3 # # #
cout.fill('#');
cout<<"543";
Flags and bit fields
Format required Flag (arg1) Bit-field (arg2)
Left justified output ios::left ios::adjustfield
Right justified output ios::right ios::adjustfield
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
setf(arg1, arg2)
arg-1: one of the formatting flags.
arg-2: bit field specifies the group to which the formatting flag belongs.
Manipulators for formatted I/O operations
Manipulators are special functions that can be included in the I/O
statements to alter the format parameters of a stream.
To access manipulators, the file <iomanip> should be included
in the program.