An Object Oriented Library

Introduction

In C++, input/output is provided through the library.

IO library facilities:

  • istream (input stream) type, which supports 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 that writes to the standard error. cerr is usually used for program error messages.
  • operator », which is used to read input from an istream object
  • operator «, which is used to write output to an ostream object
  • getline function, which takes a reference to an istream and a reference to a string and reads a word from the istream into the string

No Copy or Assign for IO Objects

Example
ofstream out1, out2;
out1 = out2; // error: cannot assign stream objects
// print function: parameter is copied
ofstream print(ofstream);
out2 = print(out2); // error: cannot copy stream objects

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Share Alike 2.5 License.