cplusplus.com cplusplus.com
cplusplus.com   C++ : Reference : IOstream Library : istream : istream
- -
C++
Information
Documentation
Reference
Articles
Sourcecode
Forum
Reference
C Library
IOstream Library
Strings library
STL Containers
STL Algorithms
IOstream Library
manipulators
classes:
· filebuf
· fstream
· ifstream
· ios
· iostream
· ios_base
· istream
· istringstream
· ofstream
· ostream
· ostringstream
· streambuf
· stringbuf
· stringstream
objects:
· cerr
· cin
· clog
· cout
types:
· fpos
· streamoff
· streampos
· streamsize
istream
· istream::istream
· istream::~istream
member classes:
· istream::sentry
member functions:
· istream::gcount
· istream::get
· istream::getline
· istream::ignore
· istream::operator>>
· istream::peek
· istream::putback
· istream::read
· istream::readsome
· istream::seekg
· istream::sync
· istream::tellg
· istream::unget

-

istream::istream constructor member
explicit  istream (streambuf * sb);

Construct object

Constructs an object, assigning initial values to the base class by calling the inherited member ios::init with sb as parameter.

Parameters

sb
pointer to a streambuf object, which is set as the associated stream buffer for the object.

Return Value

None (constructor).

Example

// istream constructor
#include <iostream>
#include <fstream>
using namespace std;

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

This code uses a filebuf object (derived from streambuf) to open the file test.txt. The buffer is passed as parameter to the constructor of the istream object is, associating it to the stream. Then the first character is read and sent to the standard output stream cout.

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

Basic template member declaration

( basic_istream<charT,traits> )
explicit basic_istream ( basic_streambuf<charT,traits>* sb );

See also

ios::init Initialize object [protected] (protected member function)

© The C++ Resources Network, 2000-2007 - All rights reserved
Spotted an error? - contact us