SlideShare a Scribd company logo
3
I/O Streams and Standard I/O Devices
• I/O: sequence of bytes (stream of bytes) from source
  to destination
   – Bytes are usually characters, unless program requires
     other types of information
• Stream: sequence of characters from source to
  destination
• Input stream: sequence of characters from an input
  device to the computer
• Output stream: sequence of characters from the
  computer to an output device

                                                             3
Most read
9
Output and Formatting Output
• Syntax of cout when used with <<


• Expression is evaluated
• Value is printed
• Manipulator is used to format the output
  – Example: endl
                                             9
Most read
17
Summary (continued)
• The manipulators setprecision, fixed,
  showpoint, setw, setfill, left, and right
  can be used for formatting output
• Include iomanip for the manipulators
  setprecision, setw, and setfill


Source:
C++ Programming: From Problem Analysis to Program
  Design, Fourth Edition

                                                    17
Most read
FORMATTED INPUT AND OUTPUT
Objectives
In this chapter, you will:
• Learn what a stream is and examine input and
   output streams
• Explore how to read data from the standard input
   device
• Learn how to use predefined functions in a program
• Learn how to write data to the standard output
   device
• Discover how to use manipulators in a program to
   format output


                                                       2
I/O Streams and Standard I/O Devices
• I/O: sequence of bytes (stream of bytes) from source
  to destination
   – Bytes are usually characters, unless program requires
     other types of information
• Stream: sequence of characters from source to
  destination
• Input stream: sequence of characters from an input
  device to the computer
• Output stream: sequence of characters from the
  computer to an output device

                                                             3
I/O Streams and Standard I/O Devices
                 (cont.)
• Use iostream header file to extract
  (receive) data from keyboard and send output
  to the screen
  – Contains definitions of two data types:
     • istream - input stream
     • ostream - output stream
  – Has two variables:
     • cin - stands for common input
     • cout - stands for common output

                                              4
I/O Streams and Standard I/O Devices
                 (cont.)
• To use cin and cout, the preprocessor
  directive #include <iostream> must be
  used
• Variable declaration is similar to:
  – istream cin;
  – ostream cout;
• Input stream variables: type istream
• Output stream variables: type ostream
                                          5
cin and the Extraction Operator >>
• The syntax of an input statement using cin
  and the extraction operator >> is:


• The extraction operator >> is binary
  – Left-side operand is an input stream variable
     • Example: cin
  – Right-side operand is a variable


                                                    6
cin and the Extraction Operator >>
              (continued)
• No difference between a single cin with
  multiple variables and multiple cin
  statements with one variable
• When scanning, >> skips all whitespace
  – Blanks and certain nonprintable characters
• >> distinguishes between character 2 and
  number 2 by the right-side operand of >>
  – If type char or int (or double), the 2 is treated
    as a character or as a number 2

                                                    7
cin and the Extraction Operator >>
           (continued)




                                     8
Output and Formatting Output
• Syntax of cout when used with <<


• Expression is evaluated
• Value is printed
• Manipulator is used to format the output
  – Example: endl
                                             9
setprecision Manipulator
• Syntax:


• Outputs decimal numbers with up to n
  decimal places
• Must include the header file iomanip:
  – #include <iomanip>



                                          10
fixed Manipulator
• fixed outputs floating-point numbers in a
  fixed decimal format
  – Example: cout << fixed;
  – Disable by using the stream member function
    unsetf
     • Example: cout.unsetf(ios::fixed);
• The manipulator scientific is used to
  output floating-point numbers in scientific
  format

                                                  11
showpoint Manipulator
• showpoint forces output to show the
  decimal point and trailing zeros
• Examples:
  – cout << showpoint;
  – cout << fixed << showpoint;




                                        12
setw
• Outputs the value of an expression in specific
  columns
  – cout << setw(5) << x << endl;
• If number of columns exceeds the number of
  columns required by the expression
  – Output of the expression is right-justified
  – Unused columns to the left are filled with spaces
• Must include the header file iomanip


                                                        13
setfill Manipulator
• Output stream variables can use setfill to
  fill unused columns with a character



• Example:
  – cout << setfill('#');



                                           14
left and right Manipulators
• left: left-justifies the output


• Disable left by using unsetf


• right: right-justifies the output


                                      15
Summary
• Stream: infinite sequence of characters from a
  source to a destination
• Input stream: from a source to a computer
• Output stream: from a computer to a
  destination
• cin: common input
• cout: common output
• To use cin and cout, include iostream
  header
                                               16
Summary (continued)
• The manipulators setprecision, fixed,
  showpoint, setw, setfill, left, and right
  can be used for formatting output
• Include iomanip for the manipulators
  setprecision, setw, and setfill


Source:
C++ Programming: From Problem Analysis to Program
  Design, Fourth Edition

                                                    17

More Related Content

What's hot (20)

File handling in c
File handling in cFile handling in c
File handling in c
aakanksha s
 
C formatted and unformatted input and output constructs
C  formatted and unformatted input and output constructsC  formatted and unformatted input and output constructs
C formatted and unformatted input and output constructs
GopikaS12
 
Tokens in C++
Tokens in C++Tokens in C++
Tokens in C++
Mahender Boda
 
Data types in C
Data types in CData types in C
Data types in C
Tarun Sharma
 
Character set of c
Character set of cCharacter set of c
Character set of c
Chandrapriya Rediex
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
Vineeta Garg
 
String in c programming
String in c programmingString in c programming
String in c programming
Devan Thakur
 
File in C language
File in C languageFile in C language
File in C language
Manash Kumar Mondal
 
Dynamic memory allocation
Dynamic memory allocationDynamic memory allocation
Dynamic memory allocation
Viji B
 
Dynamic memory allocation in c
Dynamic memory allocation in cDynamic memory allocation in c
Dynamic memory allocation in c
lavanya marichamy
 
Structure of a C program
Structure of a C programStructure of a C program
Structure of a C program
David Livingston J
 
sSCOPE RESOLUTION OPERATOR.pptx
sSCOPE RESOLUTION OPERATOR.pptxsSCOPE RESOLUTION OPERATOR.pptx
sSCOPE RESOLUTION OPERATOR.pptx
Nidhi Mehra
 
Loops in c language
Loops in c languageLoops in c language
Loops in c language
tanmaymodi4
 
Types of loops in c language
Types of loops in c languageTypes of loops in c language
Types of loops in c language
sneha2494
 
Input output statement in C
Input output statement in CInput output statement in C
Input output statement in C
Muthuganesh S
 
Strings in C
Strings in CStrings in C
Strings in C
Kamal Acharya
 
Exception handling c++
Exception handling c++Exception handling c++
Exception handling c++
Jayant Dalvi
 
Structure in C
Structure in CStructure in C
Structure in C
Kamal Acharya
 
Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C Language
Shaina Arora
 
Functions in C
Functions in CFunctions in C
Functions in C
Kamal Acharya
 
File handling in c
File handling in cFile handling in c
File handling in c
aakanksha s
 
C formatted and unformatted input and output constructs
C  formatted and unformatted input and output constructsC  formatted and unformatted input and output constructs
C formatted and unformatted input and output constructs
GopikaS12
 
Inheritance in c++
Inheritance in c++Inheritance in c++
Inheritance in c++
Vineeta Garg
 
String in c programming
String in c programmingString in c programming
String in c programming
Devan Thakur
 
Dynamic memory allocation
Dynamic memory allocationDynamic memory allocation
Dynamic memory allocation
Viji B
 
Dynamic memory allocation in c
Dynamic memory allocation in cDynamic memory allocation in c
Dynamic memory allocation in c
lavanya marichamy
 
sSCOPE RESOLUTION OPERATOR.pptx
sSCOPE RESOLUTION OPERATOR.pptxsSCOPE RESOLUTION OPERATOR.pptx
sSCOPE RESOLUTION OPERATOR.pptx
Nidhi Mehra
 
Loops in c language
Loops in c languageLoops in c language
Loops in c language
tanmaymodi4
 
Types of loops in c language
Types of loops in c languageTypes of loops in c language
Types of loops in c language
sneha2494
 
Input output statement in C
Input output statement in CInput output statement in C
Input output statement in C
Muthuganesh S
 
Exception handling c++
Exception handling c++Exception handling c++
Exception handling c++
Jayant Dalvi
 
Conditional Statement in C Language
Conditional Statement in C LanguageConditional Statement in C Language
Conditional Statement in C Language
Shaina Arora
 

Viewers also liked (20)

Managing console
Managing consoleManaging console
Managing console
Shiva Saxena
 
C++ io manipulation
C++ io manipulationC++ io manipulation
C++ io manipulation
Pedro Hugo Valencia Morales
 
Managing console input and output
Managing console input and outputManaging console input and output
Managing console input and output
gourav kottawar
 
Manipulators
ManipulatorsManipulators
Manipulators
Kamal Acharya
 
C++ Files and Streams
C++ Files and Streams C++ Files and Streams
C++ Files and Streams
Ahmed Farag
 
Console Io Operations
Console Io OperationsConsole Io Operations
Console Io Operations
archikabhatia
 
Input and output in c
Input and output in cInput and output in c
Input and output in c
Rachana Joshi
 
Managing input and output operation in c
Managing input and output operation in cManaging input and output operation in c
Managing input and output operation in c
yazad dumasia
 
Files in c++
Files in c++Files in c++
Files in c++
Selvin Josy Bai Somu
 
file handling c++
file handling c++file handling c++
file handling c++
Guddu Spy
 
Vcs26
Vcs26Vcs26
Vcs26
Malikireddy Bramhananda Reddy
 
Unit iv
Unit ivUnit iv
Unit iv
donny101
 
2 3. standard io
2 3. standard io2 3. standard io
2 3. standard io
웅식 전
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
ABHISHEK fulwadhwa
 
cpp input & output system basics
cpp input & output system basicscpp input & output system basics
cpp input & output system basics
gourav kottawar
 
Lecture 12: Classes and Files
Lecture 12: Classes and FilesLecture 12: Classes and Files
Lecture 12: Classes and Files
Dr. Md. Shohel Sayeed
 
File handling in C++
File handling in C++File handling in C++
File handling in C++
Hitesh Kumar
 
Input and output in C++
Input and output in C++Input and output in C++
Input and output in C++
Nilesh Dalvi
 
Stream classes in C++
Stream classes in C++Stream classes in C++
Stream classes in C++
Shyam Gupta
 
Data file handling in c++
Data file handling in c++Data file handling in c++
Data file handling in c++
Vineeta Garg
 
Ad

Similar to Formatted input and output (20)

C++ Ch3
C++ Ch3C++ Ch3
C++ Ch3
Venkateswarlu Vuggam
 
Lec 47.48 - stream-files
Lec 47.48 - stream-filesLec 47.48 - stream-files
Lec 47.48 - stream-files
Princess Sam
 
Managing I/O in c++
Managing I/O in c++Managing I/O in c++
Managing I/O in c++
Pranali Chaudhari
 
Object oriented programming 14 output formatting using manipulators
Object oriented programming 14 output formatting using manipulatorsObject oriented programming 14 output formatting using manipulators
Object oriented programming 14 output formatting using manipulators
Vaibhav Khanna
 
Input and output basic of c++ programming and escape sequences
Input and output basic of c++ programming and escape sequencesInput and output basic of c++ programming and escape sequences
Input and output basic of c++ programming and escape sequences
ssuserf86fba
 
Managing console input
Managing console inputManaging console input
Managing console input
rajshreemuthiah
 
Object oriented programming 13 input stream and devices in cpp
Object oriented programming 13 input stream and devices in cppObject oriented programming 13 input stream and devices in cpp
Object oriented programming 13 input stream and devices in cpp
Vaibhav Khanna
 
098ca session7 c++
098ca session7 c++098ca session7 c++
098ca session7 c++
Mukund Trivedi
 
Input and Output
Input and OutputInput and Output
Input and Output
Jason J Pulikkottil
 
Chapter 3 malik
Chapter 3 malikChapter 3 malik
Chapter 3 malik
Oshal Shah
 
Chapter 3 malik
Chapter 3 malikChapter 3 malik
Chapter 3 malik
Oshal Shah
 
Chapter 3 malik
Chapter 3 malikChapter 3 malik
Chapter 3 malik
Oshal Shah
 
programming language in c&c++
programming language in c&c++programming language in c&c++
programming language in c&c++
Haripritha
 
FILE OPERATIONS.pptx
FILE OPERATIONS.pptxFILE OPERATIONS.pptx
FILE OPERATIONS.pptx
DeepasCSE
 
iostream_fstream_intro.ppt Upstream iostream
iostream_fstream_intro.ppt Upstream iostreamiostream_fstream_intro.ppt Upstream iostream
iostream_fstream_intro.ppt Upstream iostream
pradyumna68
 
C++InputOutput.pptx
C++InputOutput.pptxC++InputOutput.pptx
C++InputOutput.pptx
ansariparveen06
 
Input and output in c++
Input and output in c++Input and output in c++
Input and output in c++
Asaye Dilbo
 
C++InputOutput.PPT
C++InputOutput.PPTC++InputOutput.PPT
C++InputOutput.PPT
KamranAli649587
 
C++filehhjglnkn,jhjgnfcbfshbkh.,lm'\;;.PPT
C++filehhjglnkn,jhjgnfcbfshbkh.,lm'\;;.PPTC++filehhjglnkn,jhjgnfcbfshbkh.,lm'\;;.PPT
C++filehhjglnkn,jhjgnfcbfshbkh.,lm'\;;.PPT
BayanbekAmantay
 
C5 c++ development environment
C5 c++ development environmentC5 c++ development environment
C5 c++ development environment
snchnchl
 
Lec 47.48 - stream-files
Lec 47.48 - stream-filesLec 47.48 - stream-files
Lec 47.48 - stream-files
Princess Sam
 
Object oriented programming 14 output formatting using manipulators
Object oriented programming 14 output formatting using manipulatorsObject oriented programming 14 output formatting using manipulators
Object oriented programming 14 output formatting using manipulators
Vaibhav Khanna
 
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
 
Object oriented programming 13 input stream and devices in cpp
Object oriented programming 13 input stream and devices in cppObject oriented programming 13 input stream and devices in cpp
Object oriented programming 13 input stream and devices in cpp
Vaibhav Khanna
 
Chapter 3 malik
Chapter 3 malikChapter 3 malik
Chapter 3 malik
Oshal Shah
 
Chapter 3 malik
Chapter 3 malikChapter 3 malik
Chapter 3 malik
Oshal Shah
 
Chapter 3 malik
Chapter 3 malikChapter 3 malik
Chapter 3 malik
Oshal Shah
 
programming language in c&c++
programming language in c&c++programming language in c&c++
programming language in c&c++
Haripritha
 
FILE OPERATIONS.pptx
FILE OPERATIONS.pptxFILE OPERATIONS.pptx
FILE OPERATIONS.pptx
DeepasCSE
 
iostream_fstream_intro.ppt Upstream iostream
iostream_fstream_intro.ppt Upstream iostreamiostream_fstream_intro.ppt Upstream iostream
iostream_fstream_intro.ppt Upstream iostream
pradyumna68
 
Input and output in c++
Input and output in c++Input and output in c++
Input and output in c++
Asaye Dilbo
 
C++filehhjglnkn,jhjgnfcbfshbkh.,lm'\;;.PPT
C++filehhjglnkn,jhjgnfcbfshbkh.,lm'\;;.PPTC++filehhjglnkn,jhjgnfcbfshbkh.,lm'\;;.PPT
C++filehhjglnkn,jhjgnfcbfshbkh.,lm'\;;.PPT
BayanbekAmantay
 
C5 c++ development environment
C5 c++ development environmentC5 c++ development environment
C5 c++ development environment
snchnchl
 
Ad

More from Online (20)

Philosophy of early childhood education 3
Philosophy of early childhood education 3Philosophy of early childhood education 3
Philosophy of early childhood education 3
Online
 
Philosophy of early childhood education 2
Philosophy of early childhood education 2Philosophy of early childhood education 2
Philosophy of early childhood education 2
Online
 
Philosophy of early childhood education 1
Philosophy of early childhood education 1Philosophy of early childhood education 1
Philosophy of early childhood education 1
Online
 
Philosophy of early childhood education 4
Philosophy of early childhood education 4Philosophy of early childhood education 4
Philosophy of early childhood education 4
Online
 
Operation and expression in c++
Operation and expression in c++Operation and expression in c++
Operation and expression in c++
Online
 
Functions
FunctionsFunctions
Functions
Online
 
Control structures selection
Control structures   selectionControl structures   selection
Control structures selection
Online
 
Control structures repetition
Control structures   repetitionControl structures   repetition
Control structures repetition
Online
 
Introduction to problem solving in c++
Introduction to problem solving in c++Introduction to problem solving in c++
Introduction to problem solving in c++
Online
 
Optical transmission technique
Optical transmission techniqueOptical transmission technique
Optical transmission technique
Online
 
Multi protocol label switching (mpls)
Multi protocol label switching (mpls)Multi protocol label switching (mpls)
Multi protocol label switching (mpls)
Online
 
Lan technologies
Lan technologiesLan technologies
Lan technologies
Online
 
Introduction to internet technology
Introduction to internet technologyIntroduction to internet technology
Introduction to internet technology
Online
 
Internet standard routing protocols
Internet standard routing protocolsInternet standard routing protocols
Internet standard routing protocols
Online
 
Internet protocol
Internet protocolInternet protocol
Internet protocol
Online
 
Application protocols
Application protocolsApplication protocols
Application protocols
Online
 
Addressing
AddressingAddressing
Addressing
Online
 
Transport protocols
Transport protocolsTransport protocols
Transport protocols
Online
 
Leadership
LeadershipLeadership
Leadership
Online
 
Introduction to management
Introduction to managementIntroduction to management
Introduction to management
Online
 
Philosophy of early childhood education 3
Philosophy of early childhood education 3Philosophy of early childhood education 3
Philosophy of early childhood education 3
Online
 
Philosophy of early childhood education 2
Philosophy of early childhood education 2Philosophy of early childhood education 2
Philosophy of early childhood education 2
Online
 
Philosophy of early childhood education 1
Philosophy of early childhood education 1Philosophy of early childhood education 1
Philosophy of early childhood education 1
Online
 
Philosophy of early childhood education 4
Philosophy of early childhood education 4Philosophy of early childhood education 4
Philosophy of early childhood education 4
Online
 
Operation and expression in c++
Operation and expression in c++Operation and expression in c++
Operation and expression in c++
Online
 
Functions
FunctionsFunctions
Functions
Online
 
Control structures selection
Control structures   selectionControl structures   selection
Control structures selection
Online
 
Control structures repetition
Control structures   repetitionControl structures   repetition
Control structures repetition
Online
 
Introduction to problem solving in c++
Introduction to problem solving in c++Introduction to problem solving in c++
Introduction to problem solving in c++
Online
 
Optical transmission technique
Optical transmission techniqueOptical transmission technique
Optical transmission technique
Online
 
Multi protocol label switching (mpls)
Multi protocol label switching (mpls)Multi protocol label switching (mpls)
Multi protocol label switching (mpls)
Online
 
Lan technologies
Lan technologiesLan technologies
Lan technologies
Online
 
Introduction to internet technology
Introduction to internet technologyIntroduction to internet technology
Introduction to internet technology
Online
 
Internet standard routing protocols
Internet standard routing protocolsInternet standard routing protocols
Internet standard routing protocols
Online
 
Internet protocol
Internet protocolInternet protocol
Internet protocol
Online
 
Application protocols
Application protocolsApplication protocols
Application protocols
Online
 
Addressing
AddressingAddressing
Addressing
Online
 
Transport protocols
Transport protocolsTransport protocols
Transport protocols
Online
 
Leadership
LeadershipLeadership
Leadership
Online
 
Introduction to management
Introduction to managementIntroduction to management
Introduction to management
Online
 

Recently uploaded (20)

PHYSIOLOGY & SPORTS INJURY by Diwakar Sir
PHYSIOLOGY & SPORTS INJURY by Diwakar SirPHYSIOLOGY & SPORTS INJURY by Diwakar Sir
PHYSIOLOGY & SPORTS INJURY by Diwakar Sir
Diwakar Kashyap
 
How to Setup Lunch in Odoo 18 - Odoo guides
How to Setup Lunch in Odoo 18 - Odoo guidesHow to Setup Lunch in Odoo 18 - Odoo guides
How to Setup Lunch in Odoo 18 - Odoo guides
Celine George
 
"Hymenoptera: A Diverse and Fascinating Order".pptx
"Hymenoptera: A Diverse and Fascinating Order".pptx"Hymenoptera: A Diverse and Fascinating Order".pptx
"Hymenoptera: A Diverse and Fascinating Order".pptx
Arshad Shaikh
 
Multicultural approach in education - B.Ed
Multicultural approach in education - B.EdMulticultural approach in education - B.Ed
Multicultural approach in education - B.Ed
prathimagowda443
 
LET´S PRACTICE GRAMMAR USING SIMPLE PAST TENSE
LET´S PRACTICE GRAMMAR USING SIMPLE PAST TENSELET´S PRACTICE GRAMMAR USING SIMPLE PAST TENSE
LET´S PRACTICE GRAMMAR USING SIMPLE PAST TENSE
OlgaLeonorTorresSnch
 
SEM II 3202 STRUCTURAL MECHANICS, B ARCH, REGULATION 2021, ANNA UNIVERSITY, R...
SEM II 3202 STRUCTURAL MECHANICS, B ARCH, REGULATION 2021, ANNA UNIVERSITY, R...SEM II 3202 STRUCTURAL MECHANICS, B ARCH, REGULATION 2021, ANNA UNIVERSITY, R...
SEM II 3202 STRUCTURAL MECHANICS, B ARCH, REGULATION 2021, ANNA UNIVERSITY, R...
RVSPSOA
 
0b - THE ROMANTIC ERA: FEELINGS AND IDENTITY.pptx
0b - THE ROMANTIC ERA: FEELINGS AND IDENTITY.pptx0b - THE ROMANTIC ERA: FEELINGS AND IDENTITY.pptx
0b - THE ROMANTIC ERA: FEELINGS AND IDENTITY.pptx
Julián Jesús Pérez Fernández
 
How to Configure Add to Cart in Odoo 18 Website
How to Configure Add to Cart in Odoo 18 WebsiteHow to Configure Add to Cart in Odoo 18 Website
How to Configure Add to Cart in Odoo 18 Website
Celine George
 
POS Reporting in Odoo 18 - Odoo 18 Slides
POS Reporting in Odoo 18 - Odoo 18 SlidesPOS Reporting in Odoo 18 - Odoo 18 Slides
POS Reporting in Odoo 18 - Odoo 18 Slides
Celine George
 
How to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time OffHow to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time Off
Celine George
 
LDMMIA About me 2025 Edition 3 College Volume
LDMMIA About me 2025 Edition 3 College VolumeLDMMIA About me 2025 Edition 3 College Volume
LDMMIA About me 2025 Edition 3 College Volume
LDM & Mia eStudios
 
Dashboard Overview in Odoo 18 - Odoo Slides
Dashboard Overview in Odoo 18 - Odoo SlidesDashboard Overview in Odoo 18 - Odoo Slides
Dashboard Overview in Odoo 18 - Odoo Slides
Celine George
 
Order: Odonata Isoptera and Thysanoptera.pptx
Order: Odonata Isoptera and Thysanoptera.pptxOrder: Odonata Isoptera and Thysanoptera.pptx
Order: Odonata Isoptera and Thysanoptera.pptx
Arshad Shaikh
 
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdfForestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
ChalaKelbessa
 
HUMAN SKELETAL SYSTEM ANATAMY AND PHYSIOLOGY
HUMAN SKELETAL SYSTEM ANATAMY AND PHYSIOLOGYHUMAN SKELETAL SYSTEM ANATAMY AND PHYSIOLOGY
HUMAN SKELETAL SYSTEM ANATAMY AND PHYSIOLOGY
DHARMENDRA SAHU
 
Introduction to Online CME for Nurse Practitioners.pdf
Introduction to Online CME for Nurse Practitioners.pdfIntroduction to Online CME for Nurse Practitioners.pdf
Introduction to Online CME for Nurse Practitioners.pdf
CME4Life
 
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdf
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdfTechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdf
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdf
TechSoup
 
Critical Thinking and Bias with Jibi Moses
Critical Thinking and Bias with Jibi MosesCritical Thinking and Bias with Jibi Moses
Critical Thinking and Bias with Jibi Moses
Excellence Foundation for South Sudan
 
How to Create a Stage or a Pipeline in Odoo 18 CRM
How to Create a Stage or a Pipeline in Odoo 18 CRMHow to Create a Stage or a Pipeline in Odoo 18 CRM
How to Create a Stage or a Pipeline in Odoo 18 CRM
Celine George
 
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
SweetytamannaMohapat
 
PHYSIOLOGY & SPORTS INJURY by Diwakar Sir
PHYSIOLOGY & SPORTS INJURY by Diwakar SirPHYSIOLOGY & SPORTS INJURY by Diwakar Sir
PHYSIOLOGY & SPORTS INJURY by Diwakar Sir
Diwakar Kashyap
 
How to Setup Lunch in Odoo 18 - Odoo guides
How to Setup Lunch in Odoo 18 - Odoo guidesHow to Setup Lunch in Odoo 18 - Odoo guides
How to Setup Lunch in Odoo 18 - Odoo guides
Celine George
 
"Hymenoptera: A Diverse and Fascinating Order".pptx
"Hymenoptera: A Diverse and Fascinating Order".pptx"Hymenoptera: A Diverse and Fascinating Order".pptx
"Hymenoptera: A Diverse and Fascinating Order".pptx
Arshad Shaikh
 
Multicultural approach in education - B.Ed
Multicultural approach in education - B.EdMulticultural approach in education - B.Ed
Multicultural approach in education - B.Ed
prathimagowda443
 
LET´S PRACTICE GRAMMAR USING SIMPLE PAST TENSE
LET´S PRACTICE GRAMMAR USING SIMPLE PAST TENSELET´S PRACTICE GRAMMAR USING SIMPLE PAST TENSE
LET´S PRACTICE GRAMMAR USING SIMPLE PAST TENSE
OlgaLeonorTorresSnch
 
SEM II 3202 STRUCTURAL MECHANICS, B ARCH, REGULATION 2021, ANNA UNIVERSITY, R...
SEM II 3202 STRUCTURAL MECHANICS, B ARCH, REGULATION 2021, ANNA UNIVERSITY, R...SEM II 3202 STRUCTURAL MECHANICS, B ARCH, REGULATION 2021, ANNA UNIVERSITY, R...
SEM II 3202 STRUCTURAL MECHANICS, B ARCH, REGULATION 2021, ANNA UNIVERSITY, R...
RVSPSOA
 
How to Configure Add to Cart in Odoo 18 Website
How to Configure Add to Cart in Odoo 18 WebsiteHow to Configure Add to Cart in Odoo 18 Website
How to Configure Add to Cart in Odoo 18 Website
Celine George
 
POS Reporting in Odoo 18 - Odoo 18 Slides
POS Reporting in Odoo 18 - Odoo 18 SlidesPOS Reporting in Odoo 18 - Odoo 18 Slides
POS Reporting in Odoo 18 - Odoo 18 Slides
Celine George
 
How to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time OffHow to Create Time Off Request in Odoo 18 Time Off
How to Create Time Off Request in Odoo 18 Time Off
Celine George
 
LDMMIA About me 2025 Edition 3 College Volume
LDMMIA About me 2025 Edition 3 College VolumeLDMMIA About me 2025 Edition 3 College Volume
LDMMIA About me 2025 Edition 3 College Volume
LDM & Mia eStudios
 
Dashboard Overview in Odoo 18 - Odoo Slides
Dashboard Overview in Odoo 18 - Odoo SlidesDashboard Overview in Odoo 18 - Odoo Slides
Dashboard Overview in Odoo 18 - Odoo Slides
Celine George
 
Order: Odonata Isoptera and Thysanoptera.pptx
Order: Odonata Isoptera and Thysanoptera.pptxOrder: Odonata Isoptera and Thysanoptera.pptx
Order: Odonata Isoptera and Thysanoptera.pptx
Arshad Shaikh
 
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdfForestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
Forestry Model Exit Exam_2025_Wollega University, Gimbi Campus.pdf
ChalaKelbessa
 
HUMAN SKELETAL SYSTEM ANATAMY AND PHYSIOLOGY
HUMAN SKELETAL SYSTEM ANATAMY AND PHYSIOLOGYHUMAN SKELETAL SYSTEM ANATAMY AND PHYSIOLOGY
HUMAN SKELETAL SYSTEM ANATAMY AND PHYSIOLOGY
DHARMENDRA SAHU
 
Introduction to Online CME for Nurse Practitioners.pdf
Introduction to Online CME for Nurse Practitioners.pdfIntroduction to Online CME for Nurse Practitioners.pdf
Introduction to Online CME for Nurse Practitioners.pdf
CME4Life
 
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdf
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdfTechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdf
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.05.28.pdf
TechSoup
 
How to Create a Stage or a Pipeline in Odoo 18 CRM
How to Create a Stage or a Pipeline in Odoo 18 CRMHow to Create a Stage or a Pipeline in Odoo 18 CRM
How to Create a Stage or a Pipeline in Odoo 18 CRM
Celine George
 
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
IDSP(INTEGRATED DISEASE SURVEILLANCE PROGRAMME...
SweetytamannaMohapat
 

Formatted input and output

  • 2. Objectives In this chapter, you will: • Learn what a stream is and examine input and output streams • Explore how to read data from the standard input device • Learn how to use predefined functions in a program • Learn how to write data to the standard output device • Discover how to use manipulators in a program to format output 2
  • 3. I/O Streams and Standard I/O Devices • I/O: sequence of bytes (stream of bytes) from source to destination – Bytes are usually characters, unless program requires other types of information • Stream: sequence of characters from source to destination • Input stream: sequence of characters from an input device to the computer • Output stream: sequence of characters from the computer to an output device 3
  • 4. I/O Streams and Standard I/O Devices (cont.) • Use iostream header file to extract (receive) data from keyboard and send output to the screen – Contains definitions of two data types: • istream - input stream • ostream - output stream – Has two variables: • cin - stands for common input • cout - stands for common output 4
  • 5. I/O Streams and Standard I/O Devices (cont.) • To use cin and cout, the preprocessor directive #include <iostream> must be used • Variable declaration is similar to: – istream cin; – ostream cout; • Input stream variables: type istream • Output stream variables: type ostream 5
  • 6. cin and the Extraction Operator >> • The syntax of an input statement using cin and the extraction operator >> is: • The extraction operator >> is binary – Left-side operand is an input stream variable • Example: cin – Right-side operand is a variable 6
  • 7. cin and the Extraction Operator >> (continued) • No difference between a single cin with multiple variables and multiple cin statements with one variable • When scanning, >> skips all whitespace – Blanks and certain nonprintable characters • >> distinguishes between character 2 and number 2 by the right-side operand of >> – If type char or int (or double), the 2 is treated as a character or as a number 2 7
  • 8. cin and the Extraction Operator >> (continued) 8
  • 9. Output and Formatting Output • Syntax of cout when used with << • Expression is evaluated • Value is printed • Manipulator is used to format the output – Example: endl 9
  • 10. setprecision Manipulator • Syntax: • Outputs decimal numbers with up to n decimal places • Must include the header file iomanip: – #include <iomanip> 10
  • 11. fixed Manipulator • fixed outputs floating-point numbers in a fixed decimal format – Example: cout << fixed; – Disable by using the stream member function unsetf • Example: cout.unsetf(ios::fixed); • The manipulator scientific is used to output floating-point numbers in scientific format 11
  • 12. showpoint Manipulator • showpoint forces output to show the decimal point and trailing zeros • Examples: – cout << showpoint; – cout << fixed << showpoint; 12
  • 13. setw • Outputs the value of an expression in specific columns – cout << setw(5) << x << endl; • If number of columns exceeds the number of columns required by the expression – Output of the expression is right-justified – Unused columns to the left are filled with spaces • Must include the header file iomanip 13
  • 14. setfill Manipulator • Output stream variables can use setfill to fill unused columns with a character • Example: – cout << setfill('#'); 14
  • 15. left and right Manipulators • left: left-justifies the output • Disable left by using unsetf • right: right-justifies the output 15
  • 16. Summary • Stream: infinite sequence of characters from a source to a destination • Input stream: from a source to a computer • Output stream: from a computer to a destination • cin: common input • cout: common output • To use cin and cout, include iostream header 16
  • 17. Summary (continued) • The manipulators setprecision, fixed, showpoint, setw, setfill, left, and right can be used for formatting output • Include iomanip for the manipulators setprecision, setw, and setfill Source: C++ Programming: From Problem Analysis to Program Design, Fourth Edition 17