SlideShare a Scribd company logo
IO STREAM
Topic
Contents
 History of stream
 Stream
 Basics of input/output
 Input/output operation
 Keywords in C++
 Standard output stream
 Standard input stream
 Un-buffered error stream(cerr)
 Buffered error stream(clog)
 Benefits
 Conclusion
History of stream
 Bjarne stroustarp, the creator of C++, wrote the first version of the stream I/O
library in 1984.
 The library has undergone a number of enhancements.
 Since this early version, including the intro of manipulators to control
formatting, and templatization to allow its use with charcter types other than
char.
 Standardization in 1998 saw the library moved into the std namespace, and
the main header changed from <iostream.h> to <iostream>.
 It is this standardized version that is converted in the rest
Introduction of stream
 A stream is a flow of data from a program to a backing store, or from a
backing store to a program.
 A stream is abstraction that represent a device on which input and output
operations are performed
 Input and output is performed in the form of sequence of byte known as
stream.
 A stream can represent many different kinds of sources and destinations,
including disk files ,devices other programs, and memory arrays.
Basic input/output in C++
 C++ comes with libraries provide us with many ways for
performing input and output.
 Input stream: If the direction of flow of byte is from device to
memory then it is called input.
 Output stream: If the direction of flow of byte is opposite then it
is called output.
I/O stream library
<iostream>
 iostream stands for standard input-output stream. This header file contains
definitions to objects like cin, cout, cerr etc.
<iomanip>
 iomanip stands for input output manipulators.
 The method is used for manipulating streams.
<fstream>
 This header file mainly describe the file stream.
 It is used to handle the data being read from a file as input or data being
written into file as output.
I/O stream library
<strstream>:
To summarize , stringstream is the convenient way to
manipulate string.
Stringstream is basically allows you to treats a string object
like a stream and use all stream functions and operates on it
<stdiostream>:
Contains information for program that mixes the C and C++ styles of I/O.
Keywords in C++
There are two keywords in C++. These are as follows;
Cout:
 It is used very often for printing outputs. It is standard output stream.
Cin:
 It is used often taking inputs respectively. It is standard input stream.
 These two methods are basic methods of taking inputs and printing output in
C++.
 To use cin and cout in C++ one must include the header file iostream in the
program.
Standard output stream(Cout)
 Usually the standard output device is the display screen.
 The C++ cout statement is the instance of the ostream class.
 It is used to produce output on the standard output device, e.g. display screen.
 The data is displayed bu using the insertion operator(<<).
#include <iostream>
using namespace std;
int main( )
{
char sample[ ] = “Geeks for Geeks”;
cout << sample << “ – A computer science portal for geeks”;
return 0;
}
Output:
Geeks for Geeks - A computer science portal for geeks.
Standard input stream(Cin)
 Usually the standard input device in computer is the keyboard.
 The C++ cin statement is the instance of the class istream.
 It is used to read inputs from the standard input device, e.g. keyboard.
 The extraction operator(>>) is used along with the object cin for reading
inputs.
#include <iostream>
using namespace std;
int main( )
{
int age;
cout << “ enter your age:” ;
cin >> age;
cout << “your age is: “ <<age;
Standard input stream(Cin)
return 0;
}
Input:
18
Output:
Enter your age :
Your age is: 18
The above program asks the user to input the age. The object cin is connected
to the input device. The age is entered by the user is extracted from cin using
the extraction ope (>>) and this data is then stored in variable age.
Input/output stream example
#include<iostream.h>
Using namespace std;
int main()
{
int a, b, sum;
cout<<“enter two number:” ;
cin>>a>>b;
sum=a+b;
cout<<“sum of the two number”;
Return 0;
}
Output:
Enter two number:3 7
Sum of the two number is 10
Benefits of stream
Increase type safety, reduce errors, allow
extensibility, and provide inheritbility.
The input(>>) operator and output(<<) operator are
typesafe.
These operators are easier to use than scanf() and
printf().
Iostream in c++

More Related Content

What's hot

Classes and objects
Classes and objectsClasses and objects
Classes and objects
Nilesh Dalvi
 
Files in c++ ppt
Files in c++ pptFiles in c++ ppt
Files in c++ ppt
Kumar
 
Function overloading ppt
Function overloading pptFunction overloading ppt
Function overloading ppt
Prof. Dr. K. Adisesha
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
Vineeta Garg
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
rprajat007
 
Functions in c
Functions in cFunctions in c
Functions in c
sunila tharagaturi
 
Input and output in C++
Input and output in C++Input and output in C++
Input and output in C++
Nilesh Dalvi
 
File handling in C++
File handling in C++File handling in C++
File handling in C++
Hitesh Kumar
 
functions of C++
functions of C++functions of C++
functions of C++
tarandeep_kaur
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
HalaiHansaika
 
Managing I/O in c++
Managing I/O in c++Managing I/O in c++
Managing I/O in c++
Pranali Chaudhari
 
File handling in c
File handling in cFile handling in c
File handling in c
David Livingston J
 
Manipulators in c++
Manipulators in c++Manipulators in c++
Manipulators in c++
Ashok Raj
 
Pointers
PointersPointers
Pointers
rajshreemuthiah
 
Exception Handling in object oriented programming using C++
Exception Handling in object oriented programming using C++Exception Handling in object oriented programming using C++
Exception Handling in object oriented programming using C++
Janki Shah
 
Data Types, Variables, and Operators
Data Types, Variables, and OperatorsData Types, Variables, and Operators
Data Types, Variables, and Operators
Marwa Ali Eissa
 
Exception handling c++
Exception handling c++Exception handling c++
Exception handling c++
Jayant Dalvi
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
Rokonuzzaman Rony
 
C fundamental
C fundamentalC fundamental
C fundamental
Selvam Edwin
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
tanmaymodi4
 

What's hot (20)

Classes and objects
Classes and objectsClasses and objects
Classes and objects
 
Files in c++ ppt
Files in c++ pptFiles in c++ ppt
Files in c++ ppt
 
Function overloading ppt
Function overloading pptFunction overloading ppt
Function overloading ppt
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
Class and object in C++
Class and object in C++Class and object in C++
Class and object in C++
 
Functions in c
Functions in cFunctions in c
Functions in c
 
Input and output in C++
Input and output in C++Input and output in C++
Input and output in C++
 
File handling in C++
File handling in C++File handling in C++
File handling in C++
 
functions of C++
functions of C++functions of C++
functions of C++
 
classes and objects in C++
classes and objects in C++classes and objects in C++
classes and objects in C++
 
Managing I/O in c++
Managing I/O in c++Managing I/O in c++
Managing I/O in c++
 
File handling in c
File handling in cFile handling in c
File handling in c
 
Manipulators in c++
Manipulators in c++Manipulators in c++
Manipulators in c++
 
Pointers
PointersPointers
Pointers
 
Exception Handling in object oriented programming using C++
Exception Handling in object oriented programming using C++Exception Handling in object oriented programming using C++
Exception Handling in object oriented programming using C++
 
Data Types, Variables, and Operators
Data Types, Variables, and OperatorsData Types, Variables, and Operators
Data Types, Variables, and Operators
 
Exception handling c++
Exception handling c++Exception handling c++
Exception handling c++
 
Functions in c++
Functions in c++Functions in c++
Functions in c++
 
C fundamental
C fundamentalC fundamental
C fundamental
 
Functions in c language
Functions in c language Functions in c language
Functions in c language
 

Similar to Iostream in c++

Lec 47.48 - stream-files
Lec 47.48 - stream-filesLec 47.48 - stream-files
Lec 47.48 - stream-files
Princess Sam
 
FILE OPERATIONS.pptx
FILE OPERATIONS.pptxFILE OPERATIONS.pptx
FILE OPERATIONS.pptx
DeepasCSE
 
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
 
File handling in_c
File handling in_cFile handling in_c
File handling in_c
sanya6900
 
C5 c++ development environment
C5 c++ development environmentC5 c++ development environment
C5 c++ development environment
snchnchl
 
Console i/o for c++
Console i/o for c++Console i/o for c++
Console i/o for c++
Darshan Radadiya
 
C_and_C++_notes.pdf
C_and_C++_notes.pdfC_and_C++_notes.pdf
C_and_C++_notes.pdf
Tigabu Yaya
 
Fp201 unit2 1
Fp201 unit2 1Fp201 unit2 1
Fp201 unit2 1
rohassanie
 
OOPS using C++
OOPS using C++OOPS using C++
OOPS using C++
cpjcollege
 
C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...
C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...
C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...
ANUSUYA S
 
Programming using c++ tool
Programming using c++ toolProgramming using c++ tool
Programming using c++ tool
Abdullah Jan
 
programming language in c&c++
programming language in c&c++programming language in c&c++
programming language in c&c++
Haripritha
 
C++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWAREC++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWARE
UNIVERSITY OF ENGINEERING AND TECHNOLOGY TAXILA
 
Preprocessor , IOSTREAM Library,IOMANIP Library
Preprocessor , IOSTREAM Library,IOMANIP LibraryPreprocessor , IOSTREAM Library,IOMANIP Library
Preprocessor , IOSTREAM Library,IOMANIP Library
Meghaj Mallick
 
Input and output in c++
Input and output in c++Input and output in c++
Input and output in c++
Asaye Dilbo
 
Workshop1
Workshop1Workshop1
Workshop1
temkin abdlkader
 
Chapter 6
Chapter 6Chapter 6
Chapter 6
siragezeynu
 
JAVA (UNIT 3)
JAVA (UNIT 3)JAVA (UNIT 3)
JAVA (UNIT 3)
SURBHI SAROHA
 
streams and files
 streams and files streams and files
streams and files
Mariam Butt
 
7512635.ppt
7512635.ppt7512635.ppt
7512635.ppt
ssuserda85e6
 

Similar to Iostream in c++ (20)

Lec 47.48 - stream-files
Lec 47.48 - stream-filesLec 47.48 - stream-files
Lec 47.48 - stream-files
 
FILE OPERATIONS.pptx
FILE OPERATIONS.pptxFILE OPERATIONS.pptx
FILE OPERATIONS.pptx
 
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
 
File handling in_c
File handling in_cFile handling in_c
File handling in_c
 
C5 c++ development environment
C5 c++ development environmentC5 c++ development environment
C5 c++ development environment
 
Console i/o for c++
Console i/o for c++Console i/o for c++
Console i/o for c++
 
C_and_C++_notes.pdf
C_and_C++_notes.pdfC_and_C++_notes.pdf
C_and_C++_notes.pdf
 
Fp201 unit2 1
Fp201 unit2 1Fp201 unit2 1
Fp201 unit2 1
 
OOPS using C++
OOPS using C++OOPS using C++
OOPS using C++
 
C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...
C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...
C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...
 
Programming using c++ tool
Programming using c++ toolProgramming using c++ tool
Programming using c++ tool
 
programming language in c&c++
programming language in c&c++programming language in c&c++
programming language in c&c++
 
C++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWAREC++ AND CATEGORIES OF SOFTWARE
C++ AND CATEGORIES OF SOFTWARE
 
Preprocessor , IOSTREAM Library,IOMANIP Library
Preprocessor , IOSTREAM Library,IOMANIP LibraryPreprocessor , IOSTREAM Library,IOMANIP Library
Preprocessor , IOSTREAM Library,IOMANIP Library
 
Input and output in c++
Input and output in c++Input and output in c++
Input and output in c++
 
Workshop1
Workshop1Workshop1
Workshop1
 
Chapter 6
Chapter 6Chapter 6
Chapter 6
 
JAVA (UNIT 3)
JAVA (UNIT 3)JAVA (UNIT 3)
JAVA (UNIT 3)
 
streams and files
 streams and files streams and files
streams and files
 
7512635.ppt
7512635.ppt7512635.ppt
7512635.ppt
 

Recently uploaded

IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
VICTOR MAESTRE RAMIREZ
 
ITSM Integration with MuleSoft.pptx
ITSM  Integration with MuleSoft.pptxITSM  Integration with MuleSoft.pptx
ITSM Integration with MuleSoft.pptx
VANDANAMOHANGOUDA
 
Data Control Language.pptx Data Control Language.pptx
Data Control Language.pptx Data Control Language.pptxData Control Language.pptx Data Control Language.pptx
Data Control Language.pptx Data Control Language.pptx
ramrag33
 
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by AnantLLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
Anant Corporation
 
An improved modulation technique suitable for a three level flying capacitor ...
An improved modulation technique suitable for a three level flying capacitor ...An improved modulation technique suitable for a three level flying capacitor ...
An improved modulation technique suitable for a three level flying capacitor ...
IJECEIAES
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
IJECEIAES
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
IJECEIAES
 
artificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptxartificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptx
GauravCar
 
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
shadow0702a
 
Design and optimization of ion propulsion drone
Design and optimization of ion propulsion droneDesign and optimization of ion propulsion drone
Design and optimization of ion propulsion drone
bjmsejournal
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
KrishnaveniKrishnara1
 
Engineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdfEngineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdf
abbyasa1014
 
Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...
Prakhyath Rai
 
Rainfall intensity duration frequency curve statistical analysis and modeling...
Rainfall intensity duration frequency curve statistical analysis and modeling...Rainfall intensity duration frequency curve statistical analysis and modeling...
Rainfall intensity duration frequency curve statistical analysis and modeling...
bijceesjournal
 
cnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classicationcnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classication
SakkaravarthiShanmug
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
insn4465
 
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
171ticu
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
IJECEIAES
 
integral complex analysis chapter 06 .pdf
integral complex analysis chapter 06 .pdfintegral complex analysis chapter 06 .pdf
integral complex analysis chapter 06 .pdf
gaafergoudaay7aga
 
BRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdfBRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdf
LAXMAREDDY22
 

Recently uploaded (20)

IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student MemberIEEE Aerospace and Electronic Systems Society as a Graduate Student Member
IEEE Aerospace and Electronic Systems Society as a Graduate Student Member
 
ITSM Integration with MuleSoft.pptx
ITSM  Integration with MuleSoft.pptxITSM  Integration with MuleSoft.pptx
ITSM Integration with MuleSoft.pptx
 
Data Control Language.pptx Data Control Language.pptx
Data Control Language.pptx Data Control Language.pptxData Control Language.pptx Data Control Language.pptx
Data Control Language.pptx Data Control Language.pptx
 
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by AnantLLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
LLM Fine Tuning with QLoRA Cassandra Lunch 4, presented by Anant
 
An improved modulation technique suitable for a three level flying capacitor ...
An improved modulation technique suitable for a three level flying capacitor ...An improved modulation technique suitable for a three level flying capacitor ...
An improved modulation technique suitable for a three level flying capacitor ...
 
Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...Advanced control scheme of doubly fed induction generator for wind turbine us...
Advanced control scheme of doubly fed induction generator for wind turbine us...
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
 
artificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptxartificial intelligence and data science contents.pptx
artificial intelligence and data science contents.pptx
 
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
Use PyCharm for remote debugging of WSL on a Windo cf5c162d672e4e58b4dde5d797...
 
Design and optimization of ion propulsion drone
Design and optimization of ion propulsion droneDesign and optimization of ion propulsion drone
Design and optimization of ion propulsion drone
 
22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt22CYT12-Unit-V-E Waste and its Management.ppt
22CYT12-Unit-V-E Waste and its Management.ppt
 
Engineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdfEngineering Drawings Lecture Detail Drawings 2014.pdf
Engineering Drawings Lecture Detail Drawings 2014.pdf
 
Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...
 
Rainfall intensity duration frequency curve statistical analysis and modeling...
Rainfall intensity duration frequency curve statistical analysis and modeling...Rainfall intensity duration frequency curve statistical analysis and modeling...
Rainfall intensity duration frequency curve statistical analysis and modeling...
 
cnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classicationcnn.pptx Convolutional neural network used for image classication
cnn.pptx Convolutional neural network used for image classication
 
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
 
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样官方认证美国密歇根州立大学毕业证学位证书原版一模一样
官方认证美国密歇根州立大学毕业证学位证书原版一模一样
 
Embedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoringEmbedded machine learning-based road conditions and driving behavior monitoring
Embedded machine learning-based road conditions and driving behavior monitoring
 
integral complex analysis chapter 06 .pdf
integral complex analysis chapter 06 .pdfintegral complex analysis chapter 06 .pdf
integral complex analysis chapter 06 .pdf
 
BRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdfBRAIN TUMOR DETECTION for seminar ppt.pdf
BRAIN TUMOR DETECTION for seminar ppt.pdf
 

Iostream in c++

  • 1.
  • 3. Contents  History of stream  Stream  Basics of input/output  Input/output operation  Keywords in C++  Standard output stream  Standard input stream  Un-buffered error stream(cerr)  Buffered error stream(clog)  Benefits  Conclusion
  • 4. History of stream  Bjarne stroustarp, the creator of C++, wrote the first version of the stream I/O library in 1984.  The library has undergone a number of enhancements.  Since this early version, including the intro of manipulators to control formatting, and templatization to allow its use with charcter types other than char.  Standardization in 1998 saw the library moved into the std namespace, and the main header changed from <iostream.h> to <iostream>.  It is this standardized version that is converted in the rest
  • 5. Introduction of stream  A stream is a flow of data from a program to a backing store, or from a backing store to a program.  A stream is abstraction that represent a device on which input and output operations are performed  Input and output is performed in the form of sequence of byte known as stream.  A stream can represent many different kinds of sources and destinations, including disk files ,devices other programs, and memory arrays.
  • 6. Basic input/output in C++  C++ comes with libraries provide us with many ways for performing input and output.  Input stream: If the direction of flow of byte is from device to memory then it is called input.  Output stream: If the direction of flow of byte is opposite then it is called output.
  • 7. I/O stream library <iostream>  iostream stands for standard input-output stream. This header file contains definitions to objects like cin, cout, cerr etc. <iomanip>  iomanip stands for input output manipulators.  The method is used for manipulating streams. <fstream>  This header file mainly describe the file stream.  It is used to handle the data being read from a file as input or data being written into file as output.
  • 8. I/O stream library <strstream>: To summarize , stringstream is the convenient way to manipulate string. Stringstream is basically allows you to treats a string object like a stream and use all stream functions and operates on it <stdiostream>: Contains information for program that mixes the C and C++ styles of I/O.
  • 9. Keywords in C++ There are two keywords in C++. These are as follows; Cout:  It is used very often for printing outputs. It is standard output stream. Cin:  It is used often taking inputs respectively. It is standard input stream.  These two methods are basic methods of taking inputs and printing output in C++.  To use cin and cout in C++ one must include the header file iostream in the program.
  • 10. Standard output stream(Cout)  Usually the standard output device is the display screen.  The C++ cout statement is the instance of the ostream class.  It is used to produce output on the standard output device, e.g. display screen.  The data is displayed bu using the insertion operator(<<). #include <iostream> using namespace std; int main( ) { char sample[ ] = “Geeks for Geeks”; cout << sample << “ – A computer science portal for geeks”; return 0; } Output: Geeks for Geeks - A computer science portal for geeks.
  • 11. Standard input stream(Cin)  Usually the standard input device in computer is the keyboard.  The C++ cin statement is the instance of the class istream.  It is used to read inputs from the standard input device, e.g. keyboard.  The extraction operator(>>) is used along with the object cin for reading inputs. #include <iostream> using namespace std; int main( ) { int age; cout << “ enter your age:” ; cin >> age; cout << “your age is: “ <<age;
  • 12. Standard input stream(Cin) return 0; } Input: 18 Output: Enter your age : Your age is: 18 The above program asks the user to input the age. The object cin is connected to the input device. The age is entered by the user is extracted from cin using the extraction ope (>>) and this data is then stored in variable age.
  • 13. Input/output stream example #include<iostream.h> Using namespace std; int main() { int a, b, sum; cout<<“enter two number:” ; cin>>a>>b; sum=a+b; cout<<“sum of the two number”; Return 0; } Output: Enter two number:3 7 Sum of the two number is 10
  • 14. Benefits of stream Increase type safety, reduce errors, allow extensibility, and provide inheritbility. The input(>>) operator and output(<<) operator are typesafe. These operators are easier to use than scanf() and printf().