public member function
<istream> <iostream>

std::istream::istream

initialization (1)
explicit istream (streambuf* sb);
initialization (1)
explicit istream (streambuf* sb);
copy (2)
istream& (const istream&) = delete;
move (3)
protected: istream& (istream&& x);
Construct object
Constructs an istream object.

(1) inititalization constructor
Assigns initial values to the components of its base classes by calling the inherited member ios::init with sb as argument.
(2) copy constructor (deleted)
Deleted: no copy constructor.
(3) move constructor (protected)
Acquires the contents of x, except its associated stream buffer: It copies x's gcount value and then calls ios::move to transfer x's ios components. x is left with a gcount value of zero, not tied, and with its associated stream buffer unchanged (all other components of x are in an unspecified but valid state after the call).

Parameters

sb
pointer to a streambuf object.
x
Another istream object.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// istream constructor
#include <iostream>     // std::ios, std::istream, std::cout
#include <fstream>      // std::filebuf

int main () {
  std::filebuf fb;
  if (fb.open ("test.txt",std::ios::in))
  {
    std::istream is(&fb);
    while (is)
      std::cout << char(is.get());
    fb.close();
  }
  return 0;
}


This example code uses a filebuf object (derived from streambuf) to open a file called test.txt. The buffer is passed as parameter to the constructor of the istream object is, associating it to the stream. Then, the program uses the input stream to print its contents to cout.

Objects of istream classes are seldom constructed directly. Generally some derived class is used (like the standard ifstream or istringstream).

Data races

The object pointed by sb may be accessed and/or modified.

Exception safety

If an exception is thrown, the only side effects may come from accessing/modifying sb.

See also

<istream>