• istream (input stream) type, which provides input operations
• ostream (output stream) type, which provides output operations
• cin, an istream object that reads the standard input
• cout, an ostream object that writes to the standard output
• cerr, an ostream object, typically used for program error messages, that writes to the standard error
• The » operator, which is used to read input from an istream object
• The « operator, which is used to write output to an ostream object
• The getline function (§ 3.2.2, p. 87), which reads a line of input from a given istream into a given string
C++ Primer P310
// Open the file in read mode
ifstream myFile("myfile.txt");
// Check if the file was opened successfully
if (myFile.is_open()) {
// Declare a string to hold each line of the file
string line;
// Read each line of the file until we reach the end
while (getline(myFile, line)) {
// Print the line to the console
cout << line << endl;
}
// Close the file
myFile.close();
} else {
// Print an error message if the file could not be opened
cout << "Error opening file!" << endl;
}