public member function
<istream> <iostream>

std::basic_istream::basic_istream

initialization (1)
explicit basic_istream (basic_streambuf<char_type,traits_type>* sb);
initialization (1)
explicit basic_istream (basic_streambuf<char_type,traits_type>* sb);
copy (2)
basic_istream& (const basic_istream&) = delete;
move (3)
protected: basic_istream& (basic_istream&& x);
Construct object
Constructs a basic_istream object.

(1) inititalization constructor
Assigns initial values to the components of its base classes by calling the inherited member basic_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 basic_ios::move to transfer x's basic_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 basic_streambuf object with the same template parameters as the basic_istream object.
char_type and traits_type are member types defined as aliases of the first and second class template parameters, respectively (see basic_istream types).
x
Another basic_istream of the same type (with the same class template arguments charT and traits).

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 basic_filebuf object (derived from basic_streambuf) to open a file called test.txt. The buffer is passed as parameter to the constructor of the basic_istream object is, associating it to the stream. Then, the program uses the input stream to print its contents to cout.

Objects of basic_istream classes are seldom constructed directly. Generally some derived class is used (like the standard basic_ifstream or basic_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