SlideShare a Scribd company logo
Lecture#18
 Every program takes some data as input and generates
processed data as output. • C++ supports set of I/O
functions.
 C++ uses the concepts of stream and stream classes to
implement its I/O operations with console and disk
files.
 In this chapter we will discuss how stream classes
support the console-oriented I/O operations.
 Stream is a sequence of bytes.
 If data is received from input devices in sequence then
it is called as source stream.
 When data is passed to output devices then it is called
destination.
 The data is received from keyboard or disk and can be
passed on to monitor or to the disk.
Input and output basic of c++ programming and escape sequences
 Data in source stream can be used as input data by
program .
 Source stream is called as input stream.
 Destination stream that collects output data from the
program is known as output stream.
Input and output basic of c++ programming and escape sequences
 C++ streams based are based on class and object
theory.
 C++ has a number of stream classes that are used to
work with console and file operations.
 These classes are known as streams classes. All these
classes are declared in the header file <iostream>.
 Classes istream and ostream are derived classes of base
class ios. •
 streambuf handles the buffer by providing the facilities
to flush and pour the buffer. • iostream is derived from
classes istream and ostream by using multiple
inheritance. •
 ios class is a virtual class which avoid ambiguity •
 ios class has an ability to handle formatted and
unformatted I/O operations.
Input and output basic of c++ programming and escape sequences
 Input stream uses cin object to read data.
 Output stream uses cout object to display data on the
screen.
 Data type is identified by these functions using operator
overloading << (insertion) and >> (extraction).
 The >> operator is overloaded in istream class
 The << operator is overloaded in ostream class
Input and output basic of c++ programming and escape sequences
 The cin is predefine object of istream class. It is
connected with the standard input device.
 The operator used in cin is >> to read the input from
the console.
 Example
Input and output basic of c++ programming and escape sequences
 The cout is predefined object of ostream
class.
 It is connected with the standard output
devices to show the result.
 The cout is used in conjunction with
stream operator << to display the output
on console.
Input and output basic of c++ programming and escape sequences
Input and output basic of c++ programming and escape sequences
Input and output basic of c++ programming and escape sequences
 cin object can be used with other member functions
such as getline(), read() etc.
 cin.get(char & ch): reads an input character and store it
in ch.
 cin.getline(char*buffer, int length): read a stream of
characters into the string buffer, it stops when
 It has read length-1 character or
 When it finds an end of line character ‘n’ or the end of
the file ‘eof’
 cin.read(char*buffer, int n):read n bytes(or until the end
of the file)from the stream into the buffer.
 cin.ignore(int n): ignore the next n characters from the
input stream.
 cin.eof( ):returns a non-zero value if the end of file(eof)
is reached.
 In C++ programming, a manipulator is a function or object
used with the input/output streams (e.g.cin, cout) to modify
the formatting or behavior of the data being read from or
written to the streams.
 Manipulators are typically used to control things like
formatting, precision, alignment, and other aspects of
input/output operations.
 Manipulators are often used with the insertion (<<) and
extraction (>>) operators to modify the behavior of the
streams. They can be applied directly to the stream or to
individual data items.
 endl: Inserts a newline character into the output stream and flushes the stream buffer.
e.g. cout << "Hello, world!" <<endl;
 setw(int width): Sets the minimum field width for the next output value.
e.g. cout << setw(10) << 42; // Output: " 42“;
 setprecision(int n): Sets the precision for floating-point values.
double value = 3.14159;
cout << setprecision(3) << value; // Output: "3.14“
 fixed: Sets the floating-point output format to fixed-point notation.
double value = 3.14159;
cout << fixed << value; // Output: "3.141590“
 scientific: Sets the floating-point output format to scientific notation.
double value = 314159000000.0;
std::cout << std::scientific << value; // Output: "3.141590e+11"
 hex, oct, dec: Sets the base for integer output to
hexadecimal, octal, or decimal respectively.
int value = 42;
cout <<hex << value; // Output: "2a"
 boolalpha: Outputs boolean values as "true" or "false"
instead of 1 or 0.
bool flag = true;
std::cout << std::boolalpha << flag; // Output: "true“
 The escape sequences are special non-printing
character that are used to control the printing behavior
of the output stream object(cout).
 These characters are not displayed in the output.
 An escape sequence is prefixed with the backslash ()
and used to control the printing behavior.
 The backslash() is called an escape character.
 These are written in single/double quotes.
 The escape sequence can be inserted at any
position of the string such as…
◦ At the beginning of the string
◦ In the middle of the string
◦ At the end of the string
 ‘n’ is used to insert a new line. It insert a new line and
the cursor moves to the beginning to the next line
 ‘t’ is used for tab. It moves the cursor one horizontal
tab stop to next tab stop.
◦ cout<<“programmingtcode”;
output is programming code
 ‘a’ stand for alarm. It causes a beep sound in the computer.
 ‘b’ stand for backspace. It moves the cursor one space back.
e.g cout<<“welcomeb”;
After execution of this statement the string welcome will be
printed and cursor move one step back and delete ‘e’.
 ‘r’ is used for return. It moves the cursor to the beginning of the current line.
 ‘’ is used to insert single quotation mark in the output
Cout<<“’welcome’”;
Output is ‘welcome’
 “” is used to insert a double quotation mark in the output.
Cout<<“”welcome””;
Output is “welcome”
 ‘f’ is used for form feed. It causes the output to the feed one paper on the printer
attached to the computer.
 ‘’ is used to insert a backslash character in the output. For example a statement is given
below using ‘’ escape sequence.
cout<<“programming”;
Output is programming
If single backslash is used there will be no effect on the output.
Input and output basic of c++ programming and escape sequences
Input and output basic of c++ programming and escape sequences
Input and output basic of c++ programming and escape sequences
Input and output basic of c++ programming and escape sequences
Input and output basic of c++ programming and escape sequences

More Related Content

PDF
Managing I/O in c++
PPTX
FILE OPERATIONS.pptx
PDF
Input and output in c++
PDF
streams and files
PPT
Chapter 3 malik
PPT
Chapter 3 malik
PPT
Chapter 3 malik
Managing I/O in c++
FILE OPERATIONS.pptx
Input and output in c++
streams and files
Chapter 3 malik
Chapter 3 malik
Chapter 3 malik

Similar to Input and output basic of c++ programming and escape sequences (20)

PPTX
programming language in c&c++
PPTX
Managing console of I/o operations & working with files
PPTX
Overloading of io stream operators
PPT
Formatted input and output
PPTX
13 file handling in C++.pptx oops object oriented programming
PPT
Lec 47.48 - stream-files
DOCX
Console i/o for c++
PPTX
Stream classes in C++
PPTX
Iostream in c++
PPT
Input and output in C++
PPTX
Managing console input
PPT
cpp input & output system basics
PPT
iostream_fstream_intro.ppt Upstream iostream
PPTX
Object oriented programming 13 input stream and devices in cpp
PPT
pengenalan mengenai computer dan programming
PDF
Input and Output
PPTX
Managing,working with files
PPTX
Managing console i/o operation,working with files
PPTX
Structure of a C++ Program in computer programming .pptx
PPTX
Object Oriented Programming Using C++: Ch12 Streams and Files.pptx
programming language in c&c++
Managing console of I/o operations & working with files
Overloading of io stream operators
Formatted input and output
13 file handling in C++.pptx oops object oriented programming
Lec 47.48 - stream-files
Console i/o for c++
Stream classes in C++
Iostream in c++
Input and output in C++
Managing console input
cpp input & output system basics
iostream_fstream_intro.ppt Upstream iostream
Object oriented programming 13 input stream and devices in cpp
pengenalan mengenai computer dan programming
Input and Output
Managing,working with files
Managing console i/o operation,working with files
Structure of a C++ Program in computer programming .pptx
Object Oriented Programming Using C++: Ch12 Streams and Files.pptx
Ad

More from ssuserf86fba (16)

PDF
Lecture 1(i). ifs about information process cyle using ict concept
PDF
Lecture 1.pdf its about introduction of information and .
PPTX
Lecture of using iict concept in c++ basic
PDF
detail of flowchart and algorithm that are used in programmingpdf
PDF
Introduction To C++ programming and its basic concepts
PDF
problem solving skills and its related all information
PDF
system and application software are used in computer.
PDF
its about computer storage and its managements how to manage the memory, in a...
PDF
computerarchitecturecachememory-170927134432.pdf
PDF
number system in introduction to computer language
PDF
introduction to computer and technology-Lecture-1.pdf
PPTX
cache memory and cloud computing technology
PDF
its about information process cycle and its components
PDF
cental processing unit and all its components
PPTX
Ipc (how we transfer the information end to end
PDF
Lecture-2-Relational-Algebra-and-SQL-Advanced-DataBase-Theory-MS.pdf
Lecture 1(i). ifs about information process cyle using ict concept
Lecture 1.pdf its about introduction of information and .
Lecture of using iict concept in c++ basic
detail of flowchart and algorithm that are used in programmingpdf
Introduction To C++ programming and its basic concepts
problem solving skills and its related all information
system and application software are used in computer.
its about computer storage and its managements how to manage the memory, in a...
computerarchitecturecachememory-170927134432.pdf
number system in introduction to computer language
introduction to computer and technology-Lecture-1.pdf
cache memory and cloud computing technology
its about information process cycle and its components
cental processing unit and all its components
Ipc (how we transfer the information end to end
Lecture-2-Relational-Algebra-and-SQL-Advanced-DataBase-Theory-MS.pdf
Ad

Recently uploaded (20)

PDF
Insiders guide to clinical Medicine.pdf
PPTX
master seminar digital applications in india
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
GDM (1) (1).pptx small presentation for students
PPTX
Cell Types and Its function , kingdom of life
PDF
Pre independence Education in Inndia.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
01-Introduction-to-Information-Management.pdf
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
Computing-Curriculum for Schools in Ghana
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
Supply Chain Operations Speaking Notes -ICLT Program
Insiders guide to clinical Medicine.pdf
master seminar digital applications in india
O5-L3 Freight Transport Ops (International) V1.pdf
GDM (1) (1).pptx small presentation for students
Cell Types and Its function , kingdom of life
Pre independence Education in Inndia.pdf
human mycosis Human fungal infections are called human mycosis..pptx
01-Introduction-to-Information-Management.pdf
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Computing-Curriculum for Schools in Ghana
FourierSeries-QuestionsWithAnswers(Part-A).pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Abdominal Access Techniques with Prof. Dr. R K Mishra
Pharmacology of Heart Failure /Pharmacotherapy of CHF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPH.pptx obstetrics and gynecology in nursing
Supply Chain Operations Speaking Notes -ICLT Program

Input and output basic of c++ programming and escape sequences

  • 2.  Every program takes some data as input and generates processed data as output. • C++ supports set of I/O functions.  C++ uses the concepts of stream and stream classes to implement its I/O operations with console and disk files.  In this chapter we will discuss how stream classes support the console-oriented I/O operations.
  • 3.  Stream is a sequence of bytes.  If data is received from input devices in sequence then it is called as source stream.  When data is passed to output devices then it is called destination.  The data is received from keyboard or disk and can be passed on to monitor or to the disk.
  • 5.  Data in source stream can be used as input data by program .  Source stream is called as input stream.  Destination stream that collects output data from the program is known as output stream.
  • 7.  C++ streams based are based on class and object theory.  C++ has a number of stream classes that are used to work with console and file operations.  These classes are known as streams classes. All these classes are declared in the header file <iostream>.
  • 8.  Classes istream and ostream are derived classes of base class ios. •  streambuf handles the buffer by providing the facilities to flush and pour the buffer. • iostream is derived from classes istream and ostream by using multiple inheritance. •  ios class is a virtual class which avoid ambiguity •  ios class has an ability to handle formatted and unformatted I/O operations.
  • 10.  Input stream uses cin object to read data.  Output stream uses cout object to display data on the screen.  Data type is identified by these functions using operator overloading << (insertion) and >> (extraction).  The >> operator is overloaded in istream class  The << operator is overloaded in ostream class
  • 12.  The cin is predefine object of istream class. It is connected with the standard input device.  The operator used in cin is >> to read the input from the console.  Example
  • 14.  The cout is predefined object of ostream class.  It is connected with the standard output devices to show the result.  The cout is used in conjunction with stream operator << to display the output on console.
  • 18.  cin object can be used with other member functions such as getline(), read() etc.  cin.get(char & ch): reads an input character and store it in ch.  cin.getline(char*buffer, int length): read a stream of characters into the string buffer, it stops when  It has read length-1 character or  When it finds an end of line character ‘n’ or the end of the file ‘eof’
  • 19.  cin.read(char*buffer, int n):read n bytes(or until the end of the file)from the stream into the buffer.  cin.ignore(int n): ignore the next n characters from the input stream.  cin.eof( ):returns a non-zero value if the end of file(eof) is reached.
  • 20.  In C++ programming, a manipulator is a function or object used with the input/output streams (e.g.cin, cout) to modify the formatting or behavior of the data being read from or written to the streams.  Manipulators are typically used to control things like formatting, precision, alignment, and other aspects of input/output operations.  Manipulators are often used with the insertion (<<) and extraction (>>) operators to modify the behavior of the streams. They can be applied directly to the stream or to individual data items.
  • 21.  endl: Inserts a newline character into the output stream and flushes the stream buffer. e.g. cout << "Hello, world!" <<endl;  setw(int width): Sets the minimum field width for the next output value. e.g. cout << setw(10) << 42; // Output: " 42“;  setprecision(int n): Sets the precision for floating-point values. double value = 3.14159; cout << setprecision(3) << value; // Output: "3.14“  fixed: Sets the floating-point output format to fixed-point notation. double value = 3.14159; cout << fixed << value; // Output: "3.141590“  scientific: Sets the floating-point output format to scientific notation. double value = 314159000000.0; std::cout << std::scientific << value; // Output: "3.141590e+11"
  • 22.  hex, oct, dec: Sets the base for integer output to hexadecimal, octal, or decimal respectively. int value = 42; cout <<hex << value; // Output: "2a"  boolalpha: Outputs boolean values as "true" or "false" instead of 1 or 0. bool flag = true; std::cout << std::boolalpha << flag; // Output: "true“
  • 23.  The escape sequences are special non-printing character that are used to control the printing behavior of the output stream object(cout).  These characters are not displayed in the output.  An escape sequence is prefixed with the backslash () and used to control the printing behavior.  The backslash() is called an escape character.  These are written in single/double quotes.
  • 24.  The escape sequence can be inserted at any position of the string such as… ◦ At the beginning of the string ◦ In the middle of the string ◦ At the end of the string
  • 25.  ‘n’ is used to insert a new line. It insert a new line and the cursor moves to the beginning to the next line  ‘t’ is used for tab. It moves the cursor one horizontal tab stop to next tab stop. ◦ cout<<“programmingtcode”; output is programming code  ‘a’ stand for alarm. It causes a beep sound in the computer.  ‘b’ stand for backspace. It moves the cursor one space back. e.g cout<<“welcomeb”; After execution of this statement the string welcome will be printed and cursor move one step back and delete ‘e’.
  • 26.  ‘r’ is used for return. It moves the cursor to the beginning of the current line.  ‘’ is used to insert single quotation mark in the output Cout<<“’welcome’”; Output is ‘welcome’  “” is used to insert a double quotation mark in the output. Cout<<“”welcome””; Output is “welcome”  ‘f’ is used for form feed. It causes the output to the feed one paper on the printer attached to the computer.  ‘’ is used to insert a backslash character in the output. For example a statement is given below using ‘’ escape sequence. cout<<“programming”; Output is programming If single backslash is used there will be no effect on the output.