尊敬的 微信汇率:1円 ≈ 0.046166 元 支付宝汇率:1円 ≈ 0.046257元 [退出登录]
SlideShare a Scribd company logo
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

Conditional statement in c
Conditional statement in cConditional statement in c
Conditional statement in c
Muthuganesh S
 
Difference between combinational and
Difference between combinational andDifference between combinational and
Difference between combinational and
Damodar Panigrahy
 
Error Detection & Recovery
Error Detection & RecoveryError Detection & Recovery
Error Detection & Recovery
Akhil Kaushik
 
Recursion in C++
Recursion in C++Recursion in C++
Recursion in C++
Maliha Mehr
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
Pranali Chaudhari
 
Constructor and Types of Constructors
Constructor and Types of ConstructorsConstructor and Types of Constructors
Constructor and Types of Constructors
Dhrumil Panchal
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
Vineeta Garg
 
Object Oriented Programming Using C++
Object Oriented Programming Using C++Object Oriented Programming Using C++
Object Oriented Programming Using C++
Muhammad Waqas
 
Functions in python slide share
Functions in python slide shareFunctions in python slide share
Functions in python slide share
Devashish Kumar
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
Paumil Patel
 
Encoders and decoders
Encoders and decodersEncoders and decoders
Encoders and decoders
DeepikaDG1
 
friend function(c++)
friend function(c++)friend function(c++)
friend function(c++)
Ritika Sharma
 
File in C language
File in C languageFile in C language
File in C language
Manash Kumar Mondal
 
Exception handling
Exception handlingException handling
Exception handling
Pranali Chaudhari
 
Oop c++class(final).ppt
Oop c++class(final).pptOop c++class(final).ppt
Oop c++class(final).ppt
Alok Kumar
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
Vineeta Garg
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
Amit Soni (CTFL)
 
File handling in c++
File handling in c++File handling in c++
Variables in C Programming
Variables in C ProgrammingVariables in C Programming
Variables in C Programming
programming9
 
Function C programming
Function C programmingFunction C programming
Function C programming
Appili Vamsi Krishna
 

What's hot (20)

Conditional statement in c
Conditional statement in cConditional statement in c
Conditional statement in c
 
Difference between combinational and
Difference between combinational andDifference between combinational and
Difference between combinational and
 
Error Detection & Recovery
Error Detection & RecoveryError Detection & Recovery
Error Detection & Recovery
 
Recursion in C++
Recursion in C++Recursion in C++
Recursion in C++
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Constructor and Types of Constructors
Constructor and Types of ConstructorsConstructor and Types of Constructors
Constructor and Types of Constructors
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
Object Oriented Programming Using C++
Object Oriented Programming Using C++Object Oriented Programming Using C++
Object Oriented Programming Using C++
 
Functions in python slide share
Functions in python slide shareFunctions in python slide share
Functions in python slide share
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
 
Encoders and decoders
Encoders and decodersEncoders and decoders
Encoders and decoders
 
friend function(c++)
friend function(c++)friend function(c++)
friend function(c++)
 
File in C language
File in C languageFile in C language
File in C language
 
Exception handling
Exception handlingException handling
Exception handling
 
Oop c++class(final).ppt
Oop c++class(final).pptOop c++class(final).ppt
Oop c++class(final).ppt
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
Object oriented programming
Object oriented programmingObject oriented programming
Object oriented programming
 
File handling in c++
File handling in c++File handling in c++
File handling in c++
 
Variables in C Programming
Variables in C ProgrammingVariables in C Programming
Variables in C Programming
 
Function C programming
Function C programmingFunction C programming
Function C programming
 

Similar to Console i/o for c++

Managing console input
Managing console inputManaging console input
Managing console input
rajshreemuthiah
 
Lec 47.48 - stream-files
Lec 47.48 - stream-filesLec 47.48 - stream-files
Lec 47.48 - stream-files
Princess Sam
 
streams and files
 streams and files streams and files
streams and files
Mariam 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.pptx
DeepasCSE
 
Console Io Operations
Console Io OperationsConsole Io Operations
Console Io Operations
archikabhatia
 
Managing,working with files
Managing,working with filesManaging,working with files
Managing,working with files
kirupasuchi1996
 
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
ramya marichamy
 
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
yazad dumasia
 
C programming session 01
C programming session 01C programming session 01
C programming session 01
Dushmanta Nath
 
Fp201 unit2 1
Fp201 unit2 1Fp201 unit2 1
Fp201 unit2 1
rohassanie
 
Stream classes in C++
Stream classes in C++Stream classes in C++
Stream classes in C++
Shyam Gupta
 
Overloading of io stream operators
Overloading of io stream operatorsOverloading of io stream operators
Overloading of io stream operators
SARAVANAN GOPALAKRISHNAN
 
Os Vanrossum
Os VanrossumOs Vanrossum
Os Vanrossum
oscon2007
 
Iostream in c++
Iostream in c++Iostream in c++
Iostream in c++
غزالة
 
7512635.ppt
7512635.ppt7512635.ppt
7512635.ppt
ssuserda85e6
 
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
ssuserf86fba
 
Managing console
Managing consoleManaging console
Managing console
Shiva Saxena
 
CP 04.pptx
CP 04.pptxCP 04.pptx
CP 04.pptx
RehmanRasheed3
 
Unit v
Unit vUnit v
Unit v
snehaarao19
 

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,working with files
Managing,working with filesManaging,working with files
Managing,working with files
 
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 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
 
Stream classes in C++
Stream classes in C++Stream classes in C++
Stream classes in C++
 
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
 

Recently uploaded

Call Girls Madurai 8824825030 Escort In Madurai service 24X7
Call Girls Madurai 8824825030 Escort In Madurai service 24X7Call Girls Madurai 8824825030 Escort In Madurai service 24X7
Call Girls Madurai 8824825030 Escort In Madurai service 24X7
Poonam Singh
 
Sachpazis_Consolidation Settlement Calculation Program-The Python Code and th...
Sachpazis_Consolidation Settlement Calculation Program-The Python Code and th...Sachpazis_Consolidation Settlement Calculation Program-The Python Code and th...
Sachpazis_Consolidation Settlement Calculation Program-The Python Code and th...
Dr.Costas Sachpazis
 
Call Girls In Tiruppur 👯‍♀️ 7339748667 🔥 Free Home Delivery Within 30 Minutes
Call Girls In Tiruppur 👯‍♀️ 7339748667 🔥 Free Home Delivery Within 30 MinutesCall Girls In Tiruppur 👯‍♀️ 7339748667 🔥 Free Home Delivery Within 30 Minutes
Call Girls In Tiruppur 👯‍♀️ 7339748667 🔥 Free Home Delivery Within 30 Minutes
kamka4105
 
Mahipalpur Call Girls Delhi 🔥 9711199012 ❄- Pick Your Dream Call Girls with 1...
Mahipalpur Call Girls Delhi 🔥 9711199012 ❄- Pick Your Dream Call Girls with 1...Mahipalpur Call Girls Delhi 🔥 9711199012 ❄- Pick Your Dream Call Girls with 1...
Mahipalpur Call Girls Delhi 🔥 9711199012 ❄- Pick Your Dream Call Girls with 1...
simrangupta87541
 
🔥 Hyderabad Call Girls  👉 9352988975 👫 High Profile Call Girls Whatsapp Numbe...
🔥 Hyderabad Call Girls  👉 9352988975 👫 High Profile Call Girls Whatsapp Numbe...🔥 Hyderabad Call Girls  👉 9352988975 👫 High Profile Call Girls Whatsapp Numbe...
🔥 Hyderabad Call Girls  👉 9352988975 👫 High Profile Call Girls Whatsapp Numbe...
aarusi sexy model
 
FUNDAMENTALS OF MECHANICAL ENGINEERING.pdf
FUNDAMENTALS OF MECHANICAL ENGINEERING.pdfFUNDAMENTALS OF MECHANICAL ENGINEERING.pdf
FUNDAMENTALS OF MECHANICAL ENGINEERING.pdf
EMERSON EDUARDO RODRIGUES
 
An In-Depth Exploration of Natural Language Processing: Evolution, Applicatio...
An In-Depth Exploration of Natural Language Processing: Evolution, Applicatio...An In-Depth Exploration of Natural Language Processing: Evolution, Applicatio...
An In-Depth Exploration of Natural Language Processing: Evolution, Applicatio...
DharmaBanothu
 
Hot Call Girls In Bangalore ✔ 9079923931 ✔ Hi I Am Divya Vip Call Girl Servic...
Hot Call Girls In Bangalore ✔ 9079923931 ✔ Hi I Am Divya Vip Call Girl Servic...Hot Call Girls In Bangalore ✔ 9079923931 ✔ Hi I Am Divya Vip Call Girl Servic...
Hot Call Girls In Bangalore ✔ 9079923931 ✔ Hi I Am Divya Vip Call Girl Servic...
Banerescorts
 
Butterfly Valves Manufacturer (LBF Series).pdf
Butterfly Valves Manufacturer (LBF Series).pdfButterfly Valves Manufacturer (LBF Series).pdf
Butterfly Valves Manufacturer (LBF Series).pdf
Lubi Valves
 
The Differences between Schedule 40 PVC Conduit Pipe and Schedule 80 PVC Conduit
The Differences between Schedule 40 PVC Conduit Pipe and Schedule 80 PVC ConduitThe Differences between Schedule 40 PVC Conduit Pipe and Schedule 80 PVC Conduit
The Differences between Schedule 40 PVC Conduit Pipe and Schedule 80 PVC Conduit
Guangdong Ctube Industry Co., Ltd.
 
Cricket management system ptoject report.pdf
Cricket management system ptoject report.pdfCricket management system ptoject report.pdf
Cricket management system ptoject report.pdf
Kamal Acharya
 
Better Builder Magazine, Issue 49 / Spring 2024
Better Builder Magazine, Issue 49 / Spring 2024Better Builder Magazine, Issue 49 / Spring 2024
Better Builder Magazine, Issue 49 / Spring 2024
Better Builder Magazine
 
Sri Guru Hargobind Ji - Bandi Chor Guru.pdf
Sri Guru Hargobind Ji - Bandi Chor Guru.pdfSri Guru Hargobind Ji - Bandi Chor Guru.pdf
Sri Guru Hargobind Ji - Bandi Chor Guru.pdf
Balvir Singh
 
High Profile Call Girls Ahmedabad 🔥 7737669865 🔥 Real Fun With Sexual Girl Av...
High Profile Call Girls Ahmedabad 🔥 7737669865 🔥 Real Fun With Sexual Girl Av...High Profile Call Girls Ahmedabad 🔥 7737669865 🔥 Real Fun With Sexual Girl Av...
High Profile Call Girls Ahmedabad 🔥 7737669865 🔥 Real Fun With Sexual Girl Av...
dABGO KI CITy kUSHINAGAR Ak47
 
Particle Swarm Optimization–Long Short-Term Memory based Channel Estimation w...
Particle Swarm Optimization–Long Short-Term Memory based Channel Estimation w...Particle Swarm Optimization–Long Short-Term Memory based Channel Estimation w...
Particle Swarm Optimization–Long Short-Term Memory based Channel Estimation w...
IJCNCJournal
 
Call Girls Nagpur 8824825030 Escort In Nagpur service 24X7
Call Girls Nagpur 8824825030 Escort In Nagpur service 24X7Call Girls Nagpur 8824825030 Escort In Nagpur service 24X7
Call Girls Nagpur 8824825030 Escort In Nagpur service 24X7
sexytaniya455
 
Intuit CRAFT demonstration presentation for sde
Intuit CRAFT demonstration presentation for sdeIntuit CRAFT demonstration presentation for sde
Intuit CRAFT demonstration presentation for sde
ShivangMishra54
 
🔥Young College Call Girls Chandigarh 💯Call Us 🔝 7737669865 🔝💃Independent Chan...
🔥Young College Call Girls Chandigarh 💯Call Us 🔝 7737669865 🔝💃Independent Chan...🔥Young College Call Girls Chandigarh 💯Call Us 🔝 7737669865 🔝💃Independent Chan...
🔥Young College Call Girls Chandigarh 💯Call Us 🔝 7737669865 🔝💃Independent Chan...
sonamrawat5631
 
Technological Innovation Management And Entrepreneurship-1.pdf
Technological Innovation Management And Entrepreneurship-1.pdfTechnological Innovation Management And Entrepreneurship-1.pdf
Technological Innovation Management And Entrepreneurship-1.pdf
tanujaharish2
 
Literature review for prompt engineering of ChatGPT.pptx
Literature review for prompt engineering of ChatGPT.pptxLiterature review for prompt engineering of ChatGPT.pptx
Literature review for prompt engineering of ChatGPT.pptx
LokerXu2
 

Recently uploaded (20)

Call Girls Madurai 8824825030 Escort In Madurai service 24X7
Call Girls Madurai 8824825030 Escort In Madurai service 24X7Call Girls Madurai 8824825030 Escort In Madurai service 24X7
Call Girls Madurai 8824825030 Escort In Madurai service 24X7
 
Sachpazis_Consolidation Settlement Calculation Program-The Python Code and th...
Sachpazis_Consolidation Settlement Calculation Program-The Python Code and th...Sachpazis_Consolidation Settlement Calculation Program-The Python Code and th...
Sachpazis_Consolidation Settlement Calculation Program-The Python Code and th...
 
Call Girls In Tiruppur 👯‍♀️ 7339748667 🔥 Free Home Delivery Within 30 Minutes
Call Girls In Tiruppur 👯‍♀️ 7339748667 🔥 Free Home Delivery Within 30 MinutesCall Girls In Tiruppur 👯‍♀️ 7339748667 🔥 Free Home Delivery Within 30 Minutes
Call Girls In Tiruppur 👯‍♀️ 7339748667 🔥 Free Home Delivery Within 30 Minutes
 
Mahipalpur Call Girls Delhi 🔥 9711199012 ❄- Pick Your Dream Call Girls with 1...
Mahipalpur Call Girls Delhi 🔥 9711199012 ❄- Pick Your Dream Call Girls with 1...Mahipalpur Call Girls Delhi 🔥 9711199012 ❄- Pick Your Dream Call Girls with 1...
Mahipalpur Call Girls Delhi 🔥 9711199012 ❄- Pick Your Dream Call Girls with 1...
 
🔥 Hyderabad Call Girls  👉 9352988975 👫 High Profile Call Girls Whatsapp Numbe...
🔥 Hyderabad Call Girls  👉 9352988975 👫 High Profile Call Girls Whatsapp Numbe...🔥 Hyderabad Call Girls  👉 9352988975 👫 High Profile Call Girls Whatsapp Numbe...
🔥 Hyderabad Call Girls  👉 9352988975 👫 High Profile Call Girls Whatsapp Numbe...
 
FUNDAMENTALS OF MECHANICAL ENGINEERING.pdf
FUNDAMENTALS OF MECHANICAL ENGINEERING.pdfFUNDAMENTALS OF MECHANICAL ENGINEERING.pdf
FUNDAMENTALS OF MECHANICAL ENGINEERING.pdf
 
An In-Depth Exploration of Natural Language Processing: Evolution, Applicatio...
An In-Depth Exploration of Natural Language Processing: Evolution, Applicatio...An In-Depth Exploration of Natural Language Processing: Evolution, Applicatio...
An In-Depth Exploration of Natural Language Processing: Evolution, Applicatio...
 
Hot Call Girls In Bangalore ✔ 9079923931 ✔ Hi I Am Divya Vip Call Girl Servic...
Hot Call Girls In Bangalore ✔ 9079923931 ✔ Hi I Am Divya Vip Call Girl Servic...Hot Call Girls In Bangalore ✔ 9079923931 ✔ Hi I Am Divya Vip Call Girl Servic...
Hot Call Girls In Bangalore ✔ 9079923931 ✔ Hi I Am Divya Vip Call Girl Servic...
 
Butterfly Valves Manufacturer (LBF Series).pdf
Butterfly Valves Manufacturer (LBF Series).pdfButterfly Valves Manufacturer (LBF Series).pdf
Butterfly Valves Manufacturer (LBF Series).pdf
 
The Differences between Schedule 40 PVC Conduit Pipe and Schedule 80 PVC Conduit
The Differences between Schedule 40 PVC Conduit Pipe and Schedule 80 PVC ConduitThe Differences between Schedule 40 PVC Conduit Pipe and Schedule 80 PVC Conduit
The Differences between Schedule 40 PVC Conduit Pipe and Schedule 80 PVC Conduit
 
Cricket management system ptoject report.pdf
Cricket management system ptoject report.pdfCricket management system ptoject report.pdf
Cricket management system ptoject report.pdf
 
Better Builder Magazine, Issue 49 / Spring 2024
Better Builder Magazine, Issue 49 / Spring 2024Better Builder Magazine, Issue 49 / Spring 2024
Better Builder Magazine, Issue 49 / Spring 2024
 
Sri Guru Hargobind Ji - Bandi Chor Guru.pdf
Sri Guru Hargobind Ji - Bandi Chor Guru.pdfSri Guru Hargobind Ji - Bandi Chor Guru.pdf
Sri Guru Hargobind Ji - Bandi Chor Guru.pdf
 
High Profile Call Girls Ahmedabad 🔥 7737669865 🔥 Real Fun With Sexual Girl Av...
High Profile Call Girls Ahmedabad 🔥 7737669865 🔥 Real Fun With Sexual Girl Av...High Profile Call Girls Ahmedabad 🔥 7737669865 🔥 Real Fun With Sexual Girl Av...
High Profile Call Girls Ahmedabad 🔥 7737669865 🔥 Real Fun With Sexual Girl Av...
 
Particle Swarm Optimization–Long Short-Term Memory based Channel Estimation w...
Particle Swarm Optimization–Long Short-Term Memory based Channel Estimation w...Particle Swarm Optimization–Long Short-Term Memory based Channel Estimation w...
Particle Swarm Optimization–Long Short-Term Memory based Channel Estimation w...
 
Call Girls Nagpur 8824825030 Escort In Nagpur service 24X7
Call Girls Nagpur 8824825030 Escort In Nagpur service 24X7Call Girls Nagpur 8824825030 Escort In Nagpur service 24X7
Call Girls Nagpur 8824825030 Escort In Nagpur service 24X7
 
Intuit CRAFT demonstration presentation for sde
Intuit CRAFT demonstration presentation for sdeIntuit CRAFT demonstration presentation for sde
Intuit CRAFT demonstration presentation for sde
 
🔥Young College Call Girls Chandigarh 💯Call Us 🔝 7737669865 🔝💃Independent Chan...
🔥Young College Call Girls Chandigarh 💯Call Us 🔝 7737669865 🔝💃Independent Chan...🔥Young College Call Girls Chandigarh 💯Call Us 🔝 7737669865 🔝💃Independent Chan...
🔥Young College Call Girls Chandigarh 💯Call Us 🔝 7737669865 🔝💃Independent Chan...
 
Technological Innovation Management And Entrepreneurship-1.pdf
Technological Innovation Management And Entrepreneurship-1.pdfTechnological Innovation Management And Entrepreneurship-1.pdf
Technological Innovation Management And Entrepreneurship-1.pdf
 
Literature review for prompt engineering of ChatGPT.pptx
Literature review for prompt engineering of ChatGPT.pptxLiterature review for prompt engineering of ChatGPT.pptx
Literature review for prompt engineering of ChatGPT.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; }
  翻译: