SLIDE 3 I/O Flashcards
sequence of bytes (stream of bytes) from source to destination
Input/Output
sequence of characters from the source to the destination
Stream
sequence of characters from an input device to the computer
Input stream
sequence of characters from the computer to an output device
Output stream
Use ________ header file to receive data from keyboard and send output to the screen
iostream
iostream contains definitions of two data types:
istream: input stream
ostream: output stream
iostream has two variables:
cin: stands for common input
cout: stands for common output
Variable declaration of istream and ostream is similar to:
istream cin;
ostream cout;
To use cin and cout, the preprocessor directive _________ must be used
include <iostream></iostream>
Input stream variables: type _____
istream
Output stream variables: type _______
ostream
The syntax of an input statement using cin and the extraction operator»_space; is
cin»_space; variable»_space; variable…;
The extraction operator»_space; is _____
binary
Left-side operand is an _________
Example: cin
Right-side operand is a __________
input stream variable
variable
Entering a char value into an int or double variable causes serious errors, called
input failure
skips leading whitespace, finds and stores only the next character
char variable
skips leading whitespace, reads + or - sign (if any), reads the digits (including decimal for floating-point variables)
int or double variable
executes when a program is run
main
(subprogram) is a set of instructions
function
Predefined functions are organized as a collection of libraries called
header file
Inputs next character (including whitespace)
Stores in memory location indicated by its argument
get function
The syntax of cin and the get function
cin.get (varChar);
is a char variable
It is the argument (or parameter) of the function
varChar
ignore function
Discards a portion of the input
The syntax to use the function ignore is:
cin.ignore (intExp, chExp);
intExp is an ______expression
chExp is a _______expression
integer
char
Places previous character extracted by the get function from an input stream back to that stream
putback function
Returns next character from the input stream
Does not remove the character from that stream
peek function
Syntax for putback
istreamVar.putback (ch);
Syntac for peek
ch=istreamVar.peek();
separates the input stream variable name from the member, or function, name
dot notation
In C++, the dot is the
member access operator
Things can go wrong during execution
Input Failure
If an error occurs when reading data
Input stream enters the
fail state
Once in a fail state, all further I/O statements using that stream are ignored
The clear Function
When the program continues to execute with whatever values are stored in variables, this function
restores the input stream to a working state
The clear Function
The syntax of the function clear is:
istreamVar.clear();
setprecision Manipulator syntax
setprecision (n)
Outputs decimal numbers with up to n decimal places
Must include the header file iomanip
#include <iomanip></iomanip>
setprecision Manipulator
outputs floating-point numbers in a fixed decimal format
fixed Manipulator
outputs floating-point numbers in scientific format
scientific manipulator
output to show the decimal point and trailing zeros
showpoint Manipulator/showpoint forces
Reading and writing of long numbers can be error prone
C++14 Digit Separator
digit separator
’ (single-quote character)
cannot be used to separate the digits of a number
commas
Outputs the value of an expression in a specified number of columns
setw
Additional formatting tools that give you more control over your output:
setfill manipulator
left and right manipulators
unsetf manipulator
Output stream variables can use setfill to fill unused columns with a character
setfill Manipulator
left-justifies the output
left manipulator
Disable left by using
unsetf
right-justifies the output
right manipulator
Two types of manipulators
Those with parameters
Those without parameters
require the iomanip header
ex. setprecision, setw, and setfill
Parameterized stream manipulators
Manipulators without parameters require the _________ header
ex. endl, fixed, scientific, showpoint, and left
iostream
An input stream variable (such as cin) and»_space; operator can read a string into a variable of the data type ________
string
Skips any leading whitespace characters
Stops reading at a whitespace character
extraction operator
reads until end of the current line
function getline
are reported by the compiler
Syntax errors
are typically not caught by the compiler
Logic errors
is an area in secondary storage to hold info
file
infinite sequence of characters from a source to a destination
Stream
from a source to a computer
Input stream
from a computer to a destination
Output stream
reads data character-by-character
get
skips data in a line
ignore
puts last character retrieved by get back to the input stream
putback
returns next character from input stream, but does not remove it
peek
Attempting to read invalid data into a variable causes the input stream to enter the _____
fail state
manipulators that can be used for formatting output
setprecision, fixed, showpoint, setw, setfill, left, and right
Include ____________ for the manipulators setprecision, setw, and setfill
iomanip