Professional Documents
Culture Documents
Introduction To Programming
Introduction To Programming
Lecture 35
Input/Output
Streams
File
Input/Output
Stream
scanf ( ) ;
printf ( ) ;
Stream
Stream is an ordered
sequence of bytes
Stream
Input/Output
Input stream object
cin
Output stream object
cout
Stream Operators
>>
<<
Example
int i ;
char c ;
cin >> i ;
cin >> c ;
Every stream has:
– A source
– A destination
State
Example
int i , j ;
cin >> i >> j ;
cout << i / j ;
Formatted
Input / Output
Member Functions
cin.get ( ) ;
c = cin.get ( ) ;
cin.get ( char c ) ;
cin.read ( char * buffer , streamsize n )
100
cin.unget ( ) ;
cin.peek ( ) ;
cout.put ( char ch ) ;
cout.write ( char * str , int n ) ;
Example
char name [ 60 ] ;
cin >> name ;
cout << name ;
Example