9781423902096_PPT_ch03 - C Programming From Problem...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 3: Input/Output
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
C++ Programming: From Problem Analysis to Program Design, Fourth Edition 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 Explore how to use the input stream functions get , ignore , putback , and peek
Background image of page 2
C++ Programming: From Problem Analysis to Program Design, Fourth Edition 3 Objectives (continued) Become familiar with input failure Learn how to write data to the standard output device Discover how to use manipulators in a program to format output Learn how to perform input and output operations with the string data type Become familiar with file input and output
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
C++ Programming: From Problem Analysis to Program Design, Fourth Edition 4 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
Background image of page 4
C++ Programming: From Problem Analysis to Program Design, Fourth Edition 5 I/O Streams and Standard I/O Devices (continued) 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
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
C++ Programming: From Problem Analysis to Program Design, Fourth Edition 6 I/O Streams and Standard I/O Devices (continued) 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
Background image of page 6
C++ Programming: From Problem Analysis to Program Design, Fourth Edition 7 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
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
C++ Programming: From Problem Analysis to Program Design, Fourth Edition 8 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
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

Page1 / 48

9781423902096_PPT_ch03 - C Programming From Problem...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online