basic_istream

basic_istream

basic_istream·gcount·get·getline·ignore·ipfx·isfx·operator>>·peek ·putback·read·readsome·seekg· ``sentry`` ·sync·tellg·unget

template <class E, class T = char_traits<E> >
    class basic_istream : virtual public basic_ios<E, T> {
public:
    class sentry;
    explicit basic_istream(basic_streambuf<E, T> *sb);
    virtual ~istream();
    bool ipfx(bool noskip = false);
    void isfx();
    basic_istream& operator>>(basic_istream& (*pf)(basic_istream&));
    basic_istream& operator>>(basic_ios<E, T>& (*pf)(basic_ios<E, T>&));
    basic_istream& operator>>(ios_base<E, T>& (*pf)(ios_base<E, T>&));
    basic_istream& operator>>(basic_streambuf<E, T> *sb);
    basic_istream& operator>>(bool& n);
    basic_istream& operator>>(short& n);
    basic_istream& operator>>(unsigned short& n);
    basic_istream& operator>>(int& n);
    basic_istream& operator>>(unsigned int& n);
    basic_istream& operator>>(long& n);
    basic_istream& operator>>(unsigned long& n);
    basic_istream& operator>>(void *& n);
    basic_istream& operator>>(float& n);
    basic_istream& operator>>(double& n);
    basic_istream& operator>>(long double& n);
    streamsize gcount() const;
    int_type get();
    basic_istream& get(E& c);
    basic_istream& get(E *s, streamsize n);
    basic_istream& get(E *s, streamsize n, E delim);
    basic_istream& get(basic_streambuf<E, T> *sb);
    basic_istream& get(baiic_streambuf<E, T> *sb, E delim);
    basic_istream& getline(E *s, streamsize n)E
    basic_istream& getline(E *s, streamsize n, E delim);
    basic_istream& ignore(streamsize n = 1,
        int_type delim = T::eof());
    int_type peek();
    basic_istream& read(E *s, streamsize n);
    streamsize readsome(E *s, streamsize n);
    basic_istream& putback(E c);
    basic_istream& unget();
    pos_type tellg();
    basic_istream& seekg(pos_type pos);
    basic_istream& seekg(off_type off, ios_base::seek_dir way);
    int sync();
    };

The template class describes an object that controls extraction of elements and encoded objects from a stream buffer with elements of type E, whose character traits are determined by the class T.

Most of the member functions that overload operator>> are formatted input functions. They follow the pattern:

    iostate state = goodbit;
    const sentry ok(*this);
    if (ok)
        {try
            {extract elements and convert
            accumulate flags in state
            store a successful conversion}
        catch (...)
            {if (exceptions() & badbit)
                throw;
            setstate(badbit); }}
    setstate(state);
    return (*this);

Many other member functions are unformatted input functions. They follow the pattern:

    iostate state = goodbit;
    count = 0;    // the value returned by gcount
    const sentry ok(*this, true);
    if (ok)
        {try
            {extract elements and deliver
            count extracted elements in count
            accumulate flags in state}
        catch (...)
            {if (rdstate() & badbit)
                throw;
            setstate(badbit); }}
    setstate(state);

Both groups of functions call setstate(eofbit) if they encounter end-of-file while extracting elements.

An object of class basic_istream<E, T> stores:

  • A virtual public base object of class basic_ios<E, T>.
  • An extraction count for the last unformatted input operation (called count in the code above).