SlideShare a Scribd company logo
1 of 7
CONSOLEI/O 1
Managing Console
I/O Operations
Prepared By : Darshan Radadiya(Computer
Engineering)
CONSOLEI/O 2
Input and Output Stream
Que:
1. Explain input and output streams in C++.
2. Explain Input stream and Output stream in brief.
3. Describe briefly the features of I/O system supported by C++.
Ans:
 I/O System in C++ is designed to work with variety of devices including terminals, disks
and tape drives.
 I/O system supplies an interface to the programmer. This interface is known as stream.
 A stream is a sequence of bytes.
 Stream acts either as source from which the input data can be obtained or as a destination
to which the output data can be sent.
 The source stream that provides data to the program is called the input stream.
 The destination stream that receives output from the program is called the output stream.
 A program extracts the bytes from an input stream and inserts bytes into an output stream.
 Data in the input stream can come from the keyboard or any file. The data in the output
stream can go to the screen or any file.
 Stream acts as an interface between the program and the Input/Output device.
 C++ contains several predefined streams like: cin and cout
 Cin represents the input stream connected with keyboard.
 Cout represents the output stream connected to the screen.
CONSOLEI/O 3
C++ Stream Classes
Que:
1. Explain C++ Stream class hierarchy.
2. List out C++ steam classes.
Ans:
 The C++ I/O system contains a hierarchy of classes. These classes are called stream
classes.
 Stream classes are used to define various streams to deal with both the console and disk
file.
 Fig. shows the hierarchy of the stream classes used for input and output operations with
the console unit.
ios class (Input/Output Stream)
- ios is the base class for istream (input stream) and ostream(output stream).
- ios class declares constants and functions that are required for handling formatted input and
output operations.
istream (Input Stream) class
- It is inherited from class ios. It declares input function such as get(), getline() and read().
ostream (Output Stream) class
- It is also inherited from class ios. It declares output functions such as put() and write().
CONSOLEI/O 4
iostream (Input/Output Stream)
- It is the Input/Output stream.
- It is inherited from istream and ostream and thus containing all the input/output operations.
- Two objects of this class cin and cout uses the overloaded operators ‘>>’ and ‘<<’.
Streambuf (Stream buffer)
- It provides interface to physical devices through buffers; it acts as a base for filebuf class used
in files.
Class Name Contents
ios (General
I/O stream
class)
 Contains basic facilities that are used by all other input and output classes.
 Also contains a pointer to a buffer object.
 Declares constants and functions that are necessary for handling formatted
input and output functions.
istream (Input
stream)
 Inherits the properties of ios.
 Declares input functions such as get(), getline() andread()
 Contains overloaded extraction operator >>
ostream
(output stream)
 Inherits the properties of ios.
 Declares output functions such as put() and write()
 Contains overloaded insertion operator <<
iostream (I/O
stream)
 Inherits the properties of ios,istream and ostream through multiple
inheritance and thus contains all the input and output functions.
streambuf  Provides an interface to physical devices through buffers.
 Acts as a base for filebuf class used ios files.
CONSOLEI/O 5
Unformatted I/O Operations
Que:
1. Explain the functions get() , put() , getline() with example.
Ans:
Overloaded Operators >> and <<
 We have used the objects cin and cout for the input and output of data of various types.
 Input and output is possible by overloading the operators >> and <<.
 The ‘>>’ operator is overloaded in the istream class.
 The ‘<<’ operator is overloaded in the ostream class.
 The following is general format for reading data from the keyboard:
cin>>a>>b>>c;
 The general form for displaying data on the screen is:
cout>>a>>b>>c;
 Example:
#include <iostream.h>
int main()
{
int a;
cout<<"Enter the number";
cin>>a;
cout<<"The value of a="<<a;
return(0);
}
put() and get() functions
 get() and put() are used to handle the single character input/output operations.
get() function:
 There are two types of get() functions:
1. get(char *)
2. get(void)
1. get(char *)
 It fetches a character including the blank space, tab and newline character.
 It assigns the input character to its argument.
 Example:
char ch;
cin.get(ch);
2. get(void)
 It fetches a character including the blank space, tab and newline character.
 It returns the input character.
CONSOLEI/O 6
 Example:
char ch;
ch=cin.get();
put() function:
 Put() function is a member of ostream class.
 It can be used to putput a line of text character by character.
 Example:
char ch=’A’;
cout.put(ch);
Example of get(char*), and put():
#include <iostream.h>
int main()
{
int a=65; char ch;
cin.get(ch);
cout.put(ch);
ch=cin.get();
cout.put(ch);
cout.put(a);
return 0;
}
getline() and write() functions
 It is used to reads a whole line of text that ends with a newline character.
 Syntax:
cin.getline (line, size);
 First argument represents the name of string and second argument indicates the number of
character to be read.
 Example:
char name[20];
int size=10;
cin.getline(name,size);
write()
 It is used to display whole line of text on output device.
 Syntax:
cout.write (line, size);
 First argument represents the name of string and second argument indicates the number of
character to be display.
 Example:
CONSOLEI/O 7
char name[20];
int size=10;
cout.write (name, size);
Example of getline() and write():
#include <iostream.h>
int main()
{
int size=5;
char name[50];
cin.getline(name,size);
cout.write(name,size);
return 0;
}

More Related Content

What's hot

Introduction to C programming
Introduction to C programmingIntroduction to C programming
Introduction to C programmingRutvik Pensionwar
 
C programing -Structure
C programing -StructureC programing -Structure
C programing -Structureshaibal sharif
 
Function overloading(c++)
Function overloading(c++)Function overloading(c++)
Function overloading(c++)Ritika Sharma
 
Stream classes in C++
Stream classes in C++Stream classes in C++
Stream classes in C++Shyam Gupta
 
Static Data Members and Member Functions
Static Data Members and Member FunctionsStatic Data Members and Member Functions
Static Data Members and Member FunctionsMOHIT AGARWAL
 
Constructors and destructors
Constructors and destructorsConstructors and destructors
Constructors and destructorsNilesh Dalvi
 
sSCOPE RESOLUTION OPERATOR.pptx
sSCOPE RESOLUTION OPERATOR.pptxsSCOPE RESOLUTION OPERATOR.pptx
sSCOPE RESOLUTION OPERATOR.pptxNidhi Mehra
 
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programmingTejaswiB4
 
File handling in C++
File handling in C++File handling in C++
File handling in C++Hitesh Kumar
 
Classes and objects
Classes and objectsClasses and objects
Classes and objectsNilesh Dalvi
 
Dynamic memory allocation in c++
Dynamic memory allocation in c++Dynamic memory allocation in c++
Dynamic memory allocation in c++Tech_MX
 
Storage classes in C
Storage classes in C Storage classes in C
Storage classes in C Self employed
 
Inline function
Inline functionInline function
Inline functionTech_MX
 

What's hot (20)

Introduction to C programming
Introduction to C programmingIntroduction to C programming
Introduction to C programming
 
Applets
AppletsApplets
Applets
 
Operators in C++
Operators in C++Operators in C++
Operators in C++
 
C programing -Structure
C programing -StructureC programing -Structure
C programing -Structure
 
Function overloading(c++)
Function overloading(c++)Function overloading(c++)
Function overloading(c++)
 
Object-oriented concepts
Object-oriented conceptsObject-oriented concepts
Object-oriented concepts
 
Stream classes in C++
Stream classes in C++Stream classes in C++
Stream classes in C++
 
Function C programming
Function C programmingFunction C programming
Function C programming
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
Static Data Members and Member Functions
Static Data Members and Member FunctionsStatic Data Members and Member Functions
Static Data Members and Member Functions
 
Constructors and destructors
Constructors and destructorsConstructors and destructors
Constructors and destructors
 
sSCOPE RESOLUTION OPERATOR.pptx
sSCOPE RESOLUTION OPERATOR.pptxsSCOPE RESOLUTION OPERATOR.pptx
sSCOPE RESOLUTION OPERATOR.pptx
 
Basic structure of c programming
Basic structure of c programmingBasic structure of c programming
Basic structure of c programming
 
File handling in C++
File handling in C++File handling in C++
File handling in C++
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Tokens in C++
Tokens in C++Tokens in C++
Tokens in C++
 
Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
Dynamic memory allocation in c++
Dynamic memory allocation in c++Dynamic memory allocation in c++
Dynamic memory allocation in c++
 
Storage classes in C
Storage classes in C Storage classes in C
Storage classes in C
 
Inline function
Inline functionInline function
Inline function
 

Similar to Console i/o for c++

Lec 47.48 - stream-files
Lec 47.48 - stream-filesLec 47.48 - stream-files
Lec 47.48 - stream-filesPrincess Sam
 
streams and files
 streams and files streams and files
streams and filesMariam Butt
 
programming language in c&c++
programming language in c&c++programming language in c&c++
programming language in c&c++Haripritha
 
FILE OPERATIONS.pptx
FILE OPERATIONS.pptxFILE OPERATIONS.pptx
FILE OPERATIONS.pptxDeepasCSE
 
Console Io Operations
Console Io OperationsConsole Io Operations
Console Io Operationsarchikabhatia
 
Managing console i/o operation,working with files
Managing console i/o operation,working with filesManaging console i/o operation,working with files
Managing console i/o operation,working with filesramya marichamy
 
Managing,working with files
Managing,working with filesManaging,working with files
Managing,working with fileskirupasuchi1996
 
Managing input and output operation in c
Managing input and output operation in cManaging input and output operation in c
Managing input and output operation in cyazad dumasia
 
C programming session 01
C programming session 01C programming session 01
C programming session 01Dushmanta Nath
 
Os Vanrossum
Os VanrossumOs Vanrossum
Os Vanrossumoscon2007
 
Input and output basic of c++ programming and escape sequences
Input and output basic of c++ programming and escape sequencesInput and output basic of c++ programming and escape sequences
Input and output basic of c++ programming and escape sequencesssuserf86fba
 
THE IO LIBRARY in C++
THE IO LIBRARY in C++THE IO LIBRARY in C++
THE IO LIBRARY in C++Prof Ansari
 

Similar to Console i/o for c++ (20)

Managing console input
Managing console inputManaging console input
Managing console input
 
Lec 47.48 - stream-files
Lec 47.48 - stream-filesLec 47.48 - stream-files
Lec 47.48 - stream-files
 
streams and files
 streams and files streams and files
streams and files
 
programming language in c&c++
programming language in c&c++programming language in c&c++
programming language in c&c++
 
FILE OPERATIONS.pptx
FILE OPERATIONS.pptxFILE OPERATIONS.pptx
FILE OPERATIONS.pptx
 
Console Io Operations
Console Io OperationsConsole Io Operations
Console Io Operations
 
Managing console i/o operation,working with files
Managing console i/o operation,working with filesManaging console i/o operation,working with files
Managing console i/o operation,working with files
 
Managing,working with files
Managing,working with filesManaging,working with files
Managing,working with files
 
Managing input and output operation in c
Managing input and output operation in cManaging input and output operation in c
Managing input and output operation in c
 
C programming session 01
C programming session 01C programming session 01
C programming session 01
 
Fp201 unit2 1
Fp201 unit2 1Fp201 unit2 1
Fp201 unit2 1
 
Overloading of io stream operators
Overloading of io stream operatorsOverloading of io stream operators
Overloading of io stream operators
 
Os Vanrossum
Os VanrossumOs Vanrossum
Os Vanrossum
 
Iostream in c++
Iostream in c++Iostream in c++
Iostream in c++
 
7512635.ppt
7512635.ppt7512635.ppt
7512635.ppt
 
Input and output basic of c++ programming and escape sequences
Input and output basic of c++ programming and escape sequencesInput and output basic of c++ programming and escape sequences
Input and output basic of c++ programming and escape sequences
 
Managing console
Managing consoleManaging console
Managing console
 
CP 04.pptx
CP 04.pptxCP 04.pptx
CP 04.pptx
 
Unit v
Unit vUnit v
Unit v
 
THE IO LIBRARY in C++
THE IO LIBRARY in C++THE IO LIBRARY in C++
THE IO LIBRARY in C++
 

Recently uploaded

Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
EduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIEduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIkoyaldeepu123
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxPoojaBan
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidNikhilNagaraju
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxk795866
 
Effects of rheological properties on mixing
Effects of rheological properties on mixingEffects of rheological properties on mixing
Effects of rheological properties on mixingviprabot1
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHC Sai Kiran
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 

Recently uploaded (20)

Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
EduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AIEduAI - E learning Platform integrated with AI
EduAI - E learning Platform integrated with AI
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Heart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptxHeart Disease Prediction using machine learning.pptx
Heart Disease Prediction using machine learning.pptx
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
main PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfidmain PPT.pptx of girls hostel security using rfid
main PPT.pptx of girls hostel security using rfid
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
Introduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptxIntroduction-To-Agricultural-Surveillance-Rover.pptx
Introduction-To-Agricultural-Surveillance-Rover.pptx
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
Effects of rheological properties on mixing
Effects of rheological properties on mixingEffects of rheological properties on mixing
Effects of rheological properties on mixing
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECH
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 

Console i/o for c++

  • 1. CONSOLEI/O 1 Managing Console I/O Operations Prepared By : Darshan Radadiya(Computer Engineering)
  • 2. CONSOLEI/O 2 Input and Output Stream Que: 1. Explain input and output streams in C++. 2. Explain Input stream and Output stream in brief. 3. Describe briefly the features of I/O system supported by C++. Ans:  I/O System in C++ is designed to work with variety of devices including terminals, disks and tape drives.  I/O system supplies an interface to the programmer. This interface is known as stream.  A stream is a sequence of bytes.  Stream acts either as source from which the input data can be obtained or as a destination to which the output data can be sent.  The source stream that provides data to the program is called the input stream.  The destination stream that receives output from the program is called the output stream.  A program extracts the bytes from an input stream and inserts bytes into an output stream.  Data in the input stream can come from the keyboard or any file. The data in the output stream can go to the screen or any file.  Stream acts as an interface between the program and the Input/Output device.  C++ contains several predefined streams like: cin and cout  Cin represents the input stream connected with keyboard.  Cout represents the output stream connected to the screen.
  • 3. CONSOLEI/O 3 C++ Stream Classes Que: 1. Explain C++ Stream class hierarchy. 2. List out C++ steam classes. Ans:  The C++ I/O system contains a hierarchy of classes. These classes are called stream classes.  Stream classes are used to define various streams to deal with both the console and disk file.  Fig. shows the hierarchy of the stream classes used for input and output operations with the console unit. ios class (Input/Output Stream) - ios is the base class for istream (input stream) and ostream(output stream). - ios class declares constants and functions that are required for handling formatted input and output operations. istream (Input Stream) class - It is inherited from class ios. It declares input function such as get(), getline() and read(). ostream (Output Stream) class - It is also inherited from class ios. It declares output functions such as put() and write().
  • 4. CONSOLEI/O 4 iostream (Input/Output Stream) - It is the Input/Output stream. - It is inherited from istream and ostream and thus containing all the input/output operations. - Two objects of this class cin and cout uses the overloaded operators ‘>>’ and ‘<<’. Streambuf (Stream buffer) - It provides interface to physical devices through buffers; it acts as a base for filebuf class used in files. Class Name Contents ios (General I/O stream class)  Contains basic facilities that are used by all other input and output classes.  Also contains a pointer to a buffer object.  Declares constants and functions that are necessary for handling formatted input and output functions. istream (Input stream)  Inherits the properties of ios.  Declares input functions such as get(), getline() andread()  Contains overloaded extraction operator >> ostream (output stream)  Inherits the properties of ios.  Declares output functions such as put() and write()  Contains overloaded insertion operator << iostream (I/O stream)  Inherits the properties of ios,istream and ostream through multiple inheritance and thus contains all the input and output functions. streambuf  Provides an interface to physical devices through buffers.  Acts as a base for filebuf class used ios files.
  • 5. CONSOLEI/O 5 Unformatted I/O Operations Que: 1. Explain the functions get() , put() , getline() with example. Ans: Overloaded Operators >> and <<  We have used the objects cin and cout for the input and output of data of various types.  Input and output is possible by overloading the operators >> and <<.  The ‘>>’ operator is overloaded in the istream class.  The ‘<<’ operator is overloaded in the ostream class.  The following is general format for reading data from the keyboard: cin>>a>>b>>c;  The general form for displaying data on the screen is: cout>>a>>b>>c;  Example: #include <iostream.h> int main() { int a; cout<<"Enter the number"; cin>>a; cout<<"The value of a="<<a; return(0); } put() and get() functions  get() and put() are used to handle the single character input/output operations. get() function:  There are two types of get() functions: 1. get(char *) 2. get(void) 1. get(char *)  It fetches a character including the blank space, tab and newline character.  It assigns the input character to its argument.  Example: char ch; cin.get(ch); 2. get(void)  It fetches a character including the blank space, tab and newline character.  It returns the input character.
  • 6. CONSOLEI/O 6  Example: char ch; ch=cin.get(); put() function:  Put() function is a member of ostream class.  It can be used to putput a line of text character by character.  Example: char ch=’A’; cout.put(ch); Example of get(char*), and put(): #include <iostream.h> int main() { int a=65; char ch; cin.get(ch); cout.put(ch); ch=cin.get(); cout.put(ch); cout.put(a); return 0; } getline() and write() functions  It is used to reads a whole line of text that ends with a newline character.  Syntax: cin.getline (line, size);  First argument represents the name of string and second argument indicates the number of character to be read.  Example: char name[20]; int size=10; cin.getline(name,size); write()  It is used to display whole line of text on output device.  Syntax: cout.write (line, size);  First argument represents the name of string and second argument indicates the number of character to be display.  Example:
  • 7. CONSOLEI/O 7 char name[20]; int size=10; cout.write (name, size); Example of getline() and write(): #include <iostream.h> int main() { int size=5; char name[50]; cin.getline(name,size); cout.write(name,size); return 0; }