SlideShare a Scribd company logo
1 of 15
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

3. distributed file system requirements
3. distributed file system requirements3. distributed file system requirements
3. distributed file system requirementsAbDul ThaYyal
 
OS - Process Concepts
OS - Process ConceptsOS - Process Concepts
OS - Process ConceptsMukesh Chinta
 
distributed shared memory
 distributed shared memory distributed shared memory
distributed shared memoryAshish Kumar
 
Mandatory access control for information security
Mandatory access control for information securityMandatory access control for information security
Mandatory access control for information securityAjit Dadresa
 
Contiguous Memory Allocation.ppt
Contiguous Memory Allocation.pptContiguous Memory Allocation.ppt
Contiguous Memory Allocation.pptinfomerlin
 
Introduction to programming
Introduction to programmingIntroduction to programming
Introduction to programmingNeeru Mittal
 
Classes and Objects
Classes and Objects  Classes and Objects
Classes and Objects yndaravind
 
Kernel mode vs user mode in linux
Kernel mode vs user mode in linuxKernel mode vs user mode in linux
Kernel mode vs user mode in linuxSiddique Ibrahim
 
file system in operating system
file system in operating systemfile system in operating system
file system in operating systemtittuajay
 
Object oriented programming c++
Object oriented programming c++Object oriented programming c++
Object oriented programming c++Ankur Pandey
 
CS9222 Advanced Operating System
CS9222 Advanced Operating SystemCS9222 Advanced Operating System
CS9222 Advanced Operating SystemKathirvel Ayyaswamy
 
Concurrency Control in Database Management System
Concurrency Control in Database Management SystemConcurrency Control in Database Management System
Concurrency Control in Database Management SystemJanki Shah
 

What's hot (20)

operating system structure
operating system structureoperating system structure
operating system structure
 
3. distributed file system requirements
3. distributed file system requirements3. distributed file system requirements
3. distributed file system requirements
 
Network operating system
Network operating systemNetwork operating system
Network operating system
 
OS - Process Concepts
OS - Process ConceptsOS - Process Concepts
OS - Process Concepts
 
java Features
java Featuresjava Features
java Features
 
distributed shared memory
 distributed shared memory distributed shared memory
distributed shared memory
 
Mandatory access control for information security
Mandatory access control for information securityMandatory access control for information security
Mandatory access control for information security
 
Linker and Loader
Linker and Loader Linker and Loader
Linker and Loader
 
Contiguous Memory Allocation.ppt
Contiguous Memory Allocation.pptContiguous Memory Allocation.ppt
Contiguous Memory Allocation.ppt
 
Introduction to programming
Introduction to programmingIntroduction to programming
Introduction to programming
 
memory hierarchy
memory hierarchymemory hierarchy
memory hierarchy
 
Classes and Objects
Classes and Objects  Classes and Objects
Classes and Objects
 
Kernel mode vs user mode in linux
Kernel mode vs user mode in linuxKernel mode vs user mode in linux
Kernel mode vs user mode in linux
 
file system in operating system
file system in operating systemfile system in operating system
file system in operating system
 
Introduction to c++ ppt 1
Introduction to c++ ppt 1Introduction to c++ ppt 1
Introduction to c++ ppt 1
 
Distributed Operating System_1
Distributed Operating System_1Distributed Operating System_1
Distributed Operating System_1
 
Object oriented programming c++
Object oriented programming c++Object oriented programming c++
Object oriented programming c++
 
CS9222 Advanced Operating System
CS9222 Advanced Operating SystemCS9222 Advanced Operating System
CS9222 Advanced Operating System
 
Chapter 3 - Processes
Chapter 3 - ProcessesChapter 3 - Processes
Chapter 3 - Processes
 
Concurrency Control in Database Management System
Concurrency Control in Database Management SystemConcurrency Control in Database Management System
Concurrency Control in Database Management System
 

Similar to Iostream in c++

Lec 47.48 - stream-files
Lec 47.48 - stream-filesLec 47.48 - stream-files
Lec 47.48 - stream-filesPrincess Sam
 
FILE OPERATIONS.pptx
FILE OPERATIONS.pptxFILE OPERATIONS.pptx
FILE OPERATIONS.pptxDeepasCSE
 
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
 
File handling in_c
File handling in_cFile handling in_c
File handling in_csanya6900
 
C5 c++ development environment
C5 c++ development environmentC5 c++ development environment
C5 c++ development environmentsnchnchl
 
Stream classes in C++
Stream classes in C++Stream classes in C++
Stream classes in C++Shyam Gupta
 
C_and_C++_notes.pdf
C_and_C++_notes.pdfC_and_C++_notes.pdf
C_and_C++_notes.pdfTigabu Yaya
 
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++ toolAbdullah Jan
 
programming language in c&c++
programming language in c&c++programming language in c&c++
programming language in c&c++Haripritha
 
Preprocessor , IOSTREAM Library,IOMANIP Library
Preprocessor , IOSTREAM Library,IOMANIP LibraryPreprocessor , IOSTREAM Library,IOMANIP Library
Preprocessor , IOSTREAM Library,IOMANIP LibraryMeghaj Mallick
 
Input and output in c++
Input and output in c++Input and output in c++
Input and output in c++Asaye Dilbo
 
streams and files
 streams and files streams and files
streams and filesMariam Butt
 

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
 
Stream classes in C++
Stream classes in C++Stream classes in C++
Stream classes in C++
 
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
 

Recently uploaded

(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineeringmalavadedarshan25
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
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
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAbhinavSharma374939
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024hassan khalil
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
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
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
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
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZTE
 

Recently uploaded (20)

(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
(RIA) Call Girls Bhosari ( 7001035870 ) HI-Fi Pune Escorts Service
 
Internship report on mechanical engineering
Internship report on mechanical engineeringInternship report on mechanical engineering
Internship report on mechanical engineering
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
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
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
Analog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog ConverterAnalog to Digital and Digital to Analog Converter
Analog to Digital and Digital to Analog Converter
 
Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024Architect Hassan Khalil Portfolio for 2024
Architect Hassan Khalil Portfolio for 2024
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
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
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptxExploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
Exploring_Network_Security_with_JA3_by_Rakesh Seal.pptx
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
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
 
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
ZXCTN 5804 / ZTE PTN / ZTE POTN / ZTE 5804 PTN / ZTE POTN 5804 ( 100/200 GE Z...
 

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().