Chapter 03

Chapter 03 - C+ Programming: From Problem Analysis to...

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

View Full Document Right Arrow Icon
C++ Programming: From Problem Analysis to Program Design, Third 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 DocumentRight Arrow Icon
C++ Programming: From Problem Analysis to Program Design, Third 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 , fill , putback , and peek
Background image of page 2
C++ Programming: From Problem Analysis to Program Design, Third 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 DocumentRight Arrow Icon
C++ Programming: From Problem Analysis to Program Design, Third Edition 4 Input/Output Streams 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, Third Edition 5 Standard I/O Devices Use iostream to extract (receive) data from keyboard and send output to the screen iostream contains definitions of two types istream - input stream ostream - output stream iostream 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 DocumentRight Arrow Icon
C++ Programming: From Problem Analysis to Program Design, Third Edition 6 Using cin and cout To use cin and cout , the preprocessor directive #include <iostream> must be used The declaration is similar to the following C++ statements: 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, Third Edition 7 cin and the Extraction Operator >> The syntax of an input statement using cin and the extraction operator >> is cin >> variable >> variable. ..; The extraction operator >> is binary The left-hand operand is an input stream variable such as cin The right-hand operand is a variable of a simple data type
Background image of page 7

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

View Full DocumentRight Arrow Icon
C++ Programming: From Problem Analysis to Program Design, Third Edition 8 Standard Input Every occurrence of >> extracts the next data item from the input stream Two variables can be read using a single cin statement No difference between a single cin with multiple variables and multiple cin statements with one variable When scanning, >> skips all whitespace Whitespace characters consist of blanks and certain nonprintable characters
Background image of page 8
C++ Programming: From Problem Analysis to Program Design, Third Edition 9 Data Type of Input
Background image of page 9

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

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/09/2008 for the course CS 150 taught by Professor Kanneko during the Spring '08 term at Old Dominion.

Page1 / 50

Chapter 03 - C+ Programming: From Problem Analysis to...

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

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