Xem mẫu
Chapter 4 – Basic Input and Output
Reading Data
Keyboard input – cin object
– >> called extraction operator Syntax: cin >> variable; Example:
cin >> income >> expense;
Reads to values typed at keyboard (separated by whitespace) to memory locations names, income, and expense
Lesson 4.1
Prompt
Message sent from program to screen Informs user what data to enter Precedes cin statement in program
int age;
cout << “Please enter your age.”<< endl; cin >> age;
Lesson 4.1
Input and Output Streams
Series of bytes in sequence Flow from device to device
Objects are regions of storage in memory
– Object used determines device stream comes from or goes to
– cin and cout are identifiers for objects defined by iostream (screen and keyboard)
Lesson 4.1
Writing Output to a File
Similar to writing to screen
Use object connected to output file Need the fstream header
#include Open file for writing
– Declare object of ofstream class
Lesson 4.2
...
- tailieumienphi.vn
nguon tai.lieu . vn