{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

Chapter 03 - C Programming From Problem Analysis to Program...

Info icon This 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
Image of page 1

Info icon This 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, 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
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
Image of page 3

Info icon This 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, 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
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
Image of page 5

Info icon This 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, 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
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
Image of page 7

Info icon This 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, 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
Image of page 8
C++ Programming: From Problem Analysis to Program Design, Third Edition 9 Data Type of Input >> distinguishes between character 2 and number 2 by the right hand operand of >>
Image of page 9

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern