SlideShare a Scribd company logo
C.Rajeswari
I-M.Sc(IT)
 Introduction
 C++ Streams
 C++ Stream Classes
 Unformatted I/O Operations
 Formatted Console I/O Operations
 Managing Output with Manipulators
 Every program takes some data as input and generates processed data as
output following the familiar input-process-output cycle.
 C++ supports a rich set of I/O functions.
 I/O methods in C++ support the concepts of OOP and I/O methods in C
cannot handle the user-defined data types such as class objects.
 C++ uses the concept of stream and stream classes to implement its I/O
operations with the console and disk files.
 The I/O system in C++ is designed to
work with a wide variety of devices
including terminals ,disk, and tape
drives.
 The I/O system supplies an interface
to the programmer that is independent
of the actual device being accessed. a
stream is a sequence of bytes.
 The data in the input stream can come
from the keyboard or any other storage
device.
 The C++ I/O system contains a hierarchy
of classes that are used to define various
streams to deal with both the console and
disk files.
 The classes are called stream classes.
These classes are declared in the header
file iostream.
 The class istream provides the facilities
for formatted and unformatted input
while the class ostream provides the
facilities for formatted output.
Class Name Contents
ios (general input/output stream class)
istream (input stream)
ostream (output stream)
iostream (input/output stream)
streambuf
•Contains basic facilities that are used by
all other input and output classes
•Also contains a pointer to a buffer
object(streambuf object)
•Inherits the properties of ios
•Declare input functions such as get(),
getline() and read()
•Contains overloaded extraction operator
>>
•Declare output functions put() and write()
•Contains overloaded insertion operator <<
•Inherits the properties of ios istream and
ostream through multiple inheritance and
thus contains all the input and output
functions
•Provides an interface to physical devices
through buffers
•Acts as a base for filebuf class used ios
files
 Overloaded operators >>and<<:
We have used the objects cin and cout (pre-defined in the iostream file) for
the input and output of data of various types.
Syn:
 Put() and get() functions:
The classes istream and ostream define two member functions get() and put()
respectively to handle the single character input/output operations. there are two
types of get() functions.
Cout<<item1<<item2<<…..<<itemN:
Example:
 Getline() and write() functions:
we can read and display a line of text more efficiently using the line-oriented
input/output functions getline() and write(). The getline() function reads a whole line
of text that ends with a newline character.
Syn:
cin.getline (line, size);
char c;
cin.get(c);
while(c !=‘n’)
{
cout<<c;
cin.get(c);
}
C++ supports a number of features that could be used for formatting the
output. These features include.
 ios class functions and flags.
 Manipulators.
 User-defined output functions.
The ios class contains a large number of member functions that wold help
us to format the ouput in a number of ways.
 Manipulators are special functions that can be included in the I/O statements to alter
the format parameters of astream.
 Defining field width: width():
We can use the width() function to define the width of a filed necessary for the
output of an item. it is a member function.
syn:
 Setting precision: precision():
By default, the floating numbers are printed with six digits after the decimal point.
However, we can specify the number of digits to be displayed after the decimal point
while printing the floating-point numbers.
Syn:
cout.width(w);
cout.precision(d);
 Filling and padding: fill():
We have been printing the values using much larger field widths than
required by the values. The unused positions of the filed are filled with white spaces.
Syn:
 Formatting flags, bit-fields and setf():
We have seen that when the function width() is used, the value is printed
right-justified in the field width created. But , it is a usual practice to print the text
left justified.
Syn:
cout.fill(ch);
cout.setf(arg1,arg2)
 Displaying trailing zeros and plus sing:
If we print the numbers 10.75,25.00 and 15.50 using a filed width of, say, eight
positions, with two digits precision.
syn:
The trailing zeros in the second and third items have been truncated.
1 0 . 7 5
2 5
1 5 . 5
 The header file iomanip provides a set of functions called manipulators
which can be used to manipulate the output formats.
 they provide the same features as that of the ios member functions and flags.
 Some manipulators are more convenient to use than their counterparts in the
ios.
Statement:
cout<<manip1<<manip2<<manip3<<item;
cout<<manip1<<item1<<item2<<item2;
 The most commonly used manipulators. The table also gives their meaning and
equivalents. To access these manipulators, we must include the file iomanip in the
program.
• Designing our own manipulators:
we can design our own manipulators for certain special purposes. The general from
for creating a manipulators. The arguments
ostream & manipulators(ostream&output)
{
……
……(code)
……
return output;
}
Managing console input

More Related Content

What's hot (20)

PPT
cpp input & output system basics
gourav kottawar
 
PPT
Formatted input and output
Online
 
PDF
Manipulators
Kamal Acharya
 
PPTX
Introduction to c++
Himanshu Kaushik
 
PPTX
COM1407: Input/ Output Functions
Hemantha Kulathilake
 
PDF
Introduction to Input/Output Functions in C
Thesis Scientist Private Limited
 
DOCX
C cheat sheet for varsity (extreme edition)
Saifur Rahman
 
PPTX
Header files of c++ unit 3 -topic 3
MOHIT TOMAR
 
PPTX
Cs1123 3 c++ overview
TAlha MAlik
 
PPTX
Introduction to C++
Sikder Tahsin Al-Amin
 
PPT
Lecture01
Xafran
 
PPTX
programming language in c&c++
Haripritha
 
PPTX
Presentation on C++ Programming Language
satvirsandhu9
 
PDF
Abstracting over Execution with Higher Kinded Types
Philip Schwarz
 
PPTX
Programming using c++ tool
Abdullah Jan
 
PDF
C++11
ppd1961
 
PPTX
C introduction by thooyavan
Thooyavan Venkatachalam
 
PPT
Al2ed chapter17
Abdullelah Al-Fahad
 
PDF
Chapter 7 - Input Output Statements in C++
Deepak Singh
 
PPTX
C programming
Nazmus Shakib Shadin
 
cpp input & output system basics
gourav kottawar
 
Formatted input and output
Online
 
Manipulators
Kamal Acharya
 
Introduction to c++
Himanshu Kaushik
 
COM1407: Input/ Output Functions
Hemantha Kulathilake
 
Introduction to Input/Output Functions in C
Thesis Scientist Private Limited
 
C cheat sheet for varsity (extreme edition)
Saifur Rahman
 
Header files of c++ unit 3 -topic 3
MOHIT TOMAR
 
Cs1123 3 c++ overview
TAlha MAlik
 
Introduction to C++
Sikder Tahsin Al-Amin
 
Lecture01
Xafran
 
programming language in c&c++
Haripritha
 
Presentation on C++ Programming Language
satvirsandhu9
 
Abstracting over Execution with Higher Kinded Types
Philip Schwarz
 
Programming using c++ tool
Abdullah Jan
 
C++11
ppd1961
 
C introduction by thooyavan
Thooyavan Venkatachalam
 
Al2ed chapter17
Abdullelah Al-Fahad
 
Chapter 7 - Input Output Statements in C++
Deepak Singh
 
C programming
Nazmus Shakib Shadin
 

Similar to Managing console input (20)

PPTX
FILE OPERATIONS.pptx
DeepasCSE
 
PPT
Lec 47.48 - stream-files
Princess Sam
 
PPTX
PRINCE PRESENTATION(1).pptx
SajalKesharwani2
 
PPTX
Managing,working with files
kirupasuchi1996
 
PPS
C programming session 01
Dushmanta Nath
 
PDF
streams and files
Mariam Butt
 
PPTX
Unit2 input output
deepak kumbhar
 
PPTX
Introduction to C Unit 1
Dr. SURBHI SAROHA
 
PPT
c.ppt
jazzcashlimit
 
PPTX
Fundamental of programming Fundamental of programming
LidetAdmassu
 
DOCX
C tutorials
Amit Kapoor
 
PDF
Input and output in c++
Asaye Dilbo
 
PPT
An Overview Of Python With Functional Programming
Adam Getchell
 
PDF
Chap 2 c++
Widad Jamaluddin
 
PPS
basics of C and c++ by eteaching
eteaching
 
PPT
C++ functions
Dawood Jutt
 
PPT
C++ functions
Dawood Jutt
 
PPTX
C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...
ANUSUYA S
 
PPTX
13 file handling in C++.pptx oops object oriented programming
archana22486y
 
PPTX
C
Jerin John
 
FILE OPERATIONS.pptx
DeepasCSE
 
Lec 47.48 - stream-files
Princess Sam
 
PRINCE PRESENTATION(1).pptx
SajalKesharwani2
 
Managing,working with files
kirupasuchi1996
 
C programming session 01
Dushmanta Nath
 
streams and files
Mariam Butt
 
Unit2 input output
deepak kumbhar
 
Introduction to C Unit 1
Dr. SURBHI SAROHA
 
Fundamental of programming Fundamental of programming
LidetAdmassu
 
C tutorials
Amit Kapoor
 
Input and output in c++
Asaye Dilbo
 
An Overview Of Python With Functional Programming
Adam Getchell
 
Chap 2 c++
Widad Jamaluddin
 
basics of C and c++ by eteaching
eteaching
 
C++ functions
Dawood Jutt
 
C++ functions
Dawood Jutt
 
C++ Unit 1PPT which contains the Introduction and basic o C++ with OOOps conc...
ANUSUYA S
 
13 file handling in C++.pptx oops object oriented programming
archana22486y
 
Ad

More from rajshreemuthiah (20)

PPTX
oracle
rajshreemuthiah
 
PPTX
quality
rajshreemuthiah
 
PPTX
bigdata
rajshreemuthiah
 
PPTX
polymorphism
rajshreemuthiah
 
PPTX
solutions and understanding text analytics
rajshreemuthiah
 
PPTX
interface
rajshreemuthiah
 
PPTX
Testing &ampdebugging
rajshreemuthiah
 
PPTX
concurrency control
rajshreemuthiah
 
PPTX
Education
rajshreemuthiah
 
PPTX
Formal verification
rajshreemuthiah
 
PPTX
Transaction management
rajshreemuthiah
 
PPTX
Multi thread
rajshreemuthiah
 
PPTX
System testing
rajshreemuthiah
 
PPTX
software maintenance
rajshreemuthiah
 
PPTX
exception handling
rajshreemuthiah
 
PPTX
e governance
rajshreemuthiah
 
PPTX
recovery management
rajshreemuthiah
 
PPTX
Implementing polymorphism
rajshreemuthiah
 
PPSX
Buffer managements
rajshreemuthiah
 
PPTX
os linux
rajshreemuthiah
 
polymorphism
rajshreemuthiah
 
solutions and understanding text analytics
rajshreemuthiah
 
interface
rajshreemuthiah
 
Testing &ampdebugging
rajshreemuthiah
 
concurrency control
rajshreemuthiah
 
Education
rajshreemuthiah
 
Formal verification
rajshreemuthiah
 
Transaction management
rajshreemuthiah
 
Multi thread
rajshreemuthiah
 
System testing
rajshreemuthiah
 
software maintenance
rajshreemuthiah
 
exception handling
rajshreemuthiah
 
e governance
rajshreemuthiah
 
recovery management
rajshreemuthiah
 
Implementing polymorphism
rajshreemuthiah
 
Buffer managements
rajshreemuthiah
 
os linux
rajshreemuthiah
 
Ad

Recently uploaded (20)

PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
July Patch Tuesday
Ivanti
 
PDF
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
PDF
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
PDF
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
PDF
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
PDF
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
July Patch Tuesday
Ivanti
 
Presentation - Vibe Coding The Future of Tech
yanuarsinggih1
 
New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
The Builder’s Playbook - 2025 State of AI Report.pdf
jeroen339954
 
Transcript: New from BookNet Canada for 2025: BNC BiblioShare - Tech Forum 2025
BookNet Canada
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
SWEBOK Guide and Software Services Engineering Education
Hironori Washizaki
 
Achieving Consistent and Reliable AI Code Generation - Medusa AI
medusaaico
 
Log-Based Anomaly Detection: Enhancing System Reliability with Machine Learning
Mohammed BEKKOUCHE
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
Bitcoin for Millennials podcast with Bram, Power Laws of Bitcoin
Stephen Perrenod
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
"AI Transformation: Directions and Challenges", Pavlo Shaternik
Fwdays
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 

Managing console input

  • 2.  Introduction  C++ Streams  C++ Stream Classes  Unformatted I/O Operations  Formatted Console I/O Operations  Managing Output with Manipulators
  • 3.  Every program takes some data as input and generates processed data as output following the familiar input-process-output cycle.  C++ supports a rich set of I/O functions.  I/O methods in C++ support the concepts of OOP and I/O methods in C cannot handle the user-defined data types such as class objects.  C++ uses the concept of stream and stream classes to implement its I/O operations with the console and disk files.
  • 4.  The I/O system in C++ is designed to work with a wide variety of devices including terminals ,disk, and tape drives.  The I/O system supplies an interface to the programmer that is independent of the actual device being accessed. a stream is a sequence of bytes.  The data in the input stream can come from the keyboard or any other storage device.
  • 5.  The C++ I/O system contains a hierarchy of classes that are used to define various streams to deal with both the console and disk files.  The classes are called stream classes. These classes are declared in the header file iostream.  The class istream provides the facilities for formatted and unformatted input while the class ostream provides the facilities for formatted output.
  • 6. Class Name Contents ios (general input/output stream class) istream (input stream) ostream (output stream) iostream (input/output stream) streambuf •Contains basic facilities that are used by all other input and output classes •Also contains a pointer to a buffer object(streambuf object) •Inherits the properties of ios •Declare input functions such as get(), getline() and read() •Contains overloaded extraction operator >> •Declare output functions put() and write() •Contains overloaded insertion operator << •Inherits the properties of ios istream and ostream through multiple inheritance and thus contains all the input and output functions •Provides an interface to physical devices through buffers •Acts as a base for filebuf class used ios files
  • 7.  Overloaded operators >>and<<: We have used the objects cin and cout (pre-defined in the iostream file) for the input and output of data of various types. Syn:  Put() and get() functions: The classes istream and ostream define two member functions get() and put() respectively to handle the single character input/output operations. there are two types of get() functions. Cout<<item1<<item2<<…..<<itemN:
  • 8. Example:  Getline() and write() functions: we can read and display a line of text more efficiently using the line-oriented input/output functions getline() and write(). The getline() function reads a whole line of text that ends with a newline character. Syn: cin.getline (line, size); char c; cin.get(c); while(c !=‘n’) { cout<<c; cin.get(c); }
  • 9. C++ supports a number of features that could be used for formatting the output. These features include.  ios class functions and flags.  Manipulators.  User-defined output functions. The ios class contains a large number of member functions that wold help us to format the ouput in a number of ways.
  • 10.  Manipulators are special functions that can be included in the I/O statements to alter the format parameters of astream.
  • 11.  Defining field width: width(): We can use the width() function to define the width of a filed necessary for the output of an item. it is a member function. syn:  Setting precision: precision(): By default, the floating numbers are printed with six digits after the decimal point. However, we can specify the number of digits to be displayed after the decimal point while printing the floating-point numbers. Syn: cout.width(w); cout.precision(d);
  • 12.  Filling and padding: fill(): We have been printing the values using much larger field widths than required by the values. The unused positions of the filed are filled with white spaces. Syn:  Formatting flags, bit-fields and setf(): We have seen that when the function width() is used, the value is printed right-justified in the field width created. But , it is a usual practice to print the text left justified. Syn: cout.fill(ch); cout.setf(arg1,arg2)
  • 13.  Displaying trailing zeros and plus sing: If we print the numbers 10.75,25.00 and 15.50 using a filed width of, say, eight positions, with two digits precision. syn: The trailing zeros in the second and third items have been truncated. 1 0 . 7 5 2 5 1 5 . 5
  • 14.  The header file iomanip provides a set of functions called manipulators which can be used to manipulate the output formats.  they provide the same features as that of the ios member functions and flags.  Some manipulators are more convenient to use than their counterparts in the ios. Statement: cout<<manip1<<manip2<<manip3<<item; cout<<manip1<<item1<<item2<<item2;
  • 15.  The most commonly used manipulators. The table also gives their meaning and equivalents. To access these manipulators, we must include the file iomanip in the program.
  • 16. • Designing our own manipulators: we can design our own manipulators for certain special purposes. The general from for creating a manipulators. The arguments ostream & manipulators(ostream&output) { …… ……(code) …… return output; }