Engineering Science 1036A/B Lecture Notes - Lecture 5: Standard Streams, Backslash
Input: cin
istream object
•
Inputs any non-whitespace data from the standard input (console/keyboard) on
to a declared variable
•
Stands for console input
•
General form: cin >> var1>>var2;
•
Uses the >> (input) operator which can extract any non-whitespace data from
the standard input
>> is known as the data extraction operator
○
•
Never use endl within cin statement
First value entered form the keyboard will be assigned to var1 while the
second one will be assigned to var2
○
•
cout statement precedes cin statement to prompt user to enter data
•
Output: cout
ostream object
•
Displays a message and/or data to the standard output (console or monitor)
•
stands for console output
•
General form: cout <<expression <<expression;
An expression can be:
String constant: one or more characters enclosed by "
§
Character constant: single character enclosed by '
§
Identifier: variable name
§
Formula: arithmetic and/or logical expressions
§
Function call
§
○
•
<< operator : stream insertion operator
Sends a processed stream to a console
○
•
•
Backslash Codes with cout
Aka "escape sequence"•
Need to be used as string constants
Enclosed in a pair of double quotation marks
○
•
Standard Input/output