• 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

Mode FlagDescription
ios::inOpen for input operations.
ios::outOpen for output operations.
ios::binaryOpen in binary mode.
ios::ateSet the initial position at the end of the file. If this flag is not set, the initial position is the beginning of the file.
ios::appAll output operations are performed at the end of the file, appending the content to the current content of the file.
ios::truncIf the file is opened for output operations and it already existed, its previous content is deleted and replaced by the new one.
classdefault mode parameter
ofstreamios::out
ifstreamios::in
fstreamios::in | ios::out

Example

// 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;
}