DIGITAL logo   C++ Graphic
    Updated: 21 April 1999
  DEC C++

DEC C++
Class Library Reference Manual


Previous Contents Index

Outputs x in at least six characters, but uses only as many characters as needed for the separating space and y.

In the following examples, mystrm is an ios object.
#2

mystrm.clear(ios::badbit|s.rdstate()) 
      

Sets the badbit member of the io_state enumerated data type without clearing previously set bits.

#3

mystrm.setf(ios::hex,ios::basefield) 
      

Changes the conversion base in mystrm to be hexadecimal.


iostream class

Provides the means to both insert into and extract from a single sequence of characters.

Header File

#include <iostream.hxx>

Alternative Header

#include <iostream.h>


Declaration


class iostream: public istream, public ostream 
{ 
public: 
               iostream(streambuf *); 
    virtual    ~iostream(); 
 
protected: 
               iostream(); 
}; 


Description

This class combines the istream and ostream classes. You use it to carry out bidirectional operations (inserting into and extracting from a single sequence of characters).

Constructors and Destructors

iostream()

Constructs an iostream object, in undefined form, to enable inheritance by derived classes.

iostream(streambuf *b)

Constructs an iostream object. It initializes ios state variables and associates the iostream object with the streambuf object pointed to by b.

virtual ~iostream()

Deletes an iostream object.

iostream_withassign class

Adds an assignment operator and a constructor with no operands to the iostream class.

Header File

#include <iostream.hxx>

Alternative Header

#include <iostream.h>


Declaration


class iostream_withassign: public iostream 
{ 
public: 
                   iostream_withassign(); 
    virtual       ~iostream_withassign(); 
 
    iostream_withassign &operator=(iostream &); 
    iostream_withassign &operator=(streambuf *); 
}; 


Description

This class adds an assignment operator and a constructor with no operands to the iostream class.

Constructors and Destructors

iostream_withassign()

Constructs an iostream_withassign object; it does no initialization.

virtual ~iostream_withassign()

Deletes an iostream_withassign object; no user action is required.

Overloaded Operators

iostream_withassign &operator = (iostream &)

Associates iostream->rdbuf() with an iostream_withassign object and initializes the entire state of that object.

iostream_withassign &operator = (streambuf *)

Associates streambuf* with an iostream_withassign object and initializes the entire state of that object.

istream class

Supports interpretation of characters extracted from an associated streambuf object.

Header File

#include <iostream.hxx>

Alternative Header

#include <iostream.h>


Declaration


class istream : virtual public ios 
{ 
public: 
                       istream(streambuf *); 
    virtual            ~istream(); 
 
    inline int         gcount(); 
    istream            &get(char *ptr, int len, 
                             char delim = '\n'); 
    istream            &get(unsigned char *ptr, int len, 
                             char delim = '\n'); 
    istream            &get(char &); 
    inline istream     &get(unsigned char &); 
    istream            &get(streambuf &sb, char delim = '\n'); 
    int                get(); 
    istream            &getline(char *ptr, int len, 
                             char delim = '\n'); 
    istream            &getline(unsigned char *ptr, int len, 
                              char delim = '\n'); 
    istream            &ignore(int len = 1, 
                             int delim = ); 
    int                ipfx(int need = 0); 
    void               isfx(); 
    int                peek(); 
    istream            &putback(char); 
    istream            &read(char *s, int n); 
    inline istream     &read(unsigned char *s, int n); 
    istream            &seekg(streampos); 
    istream            &seekg(streamoff, seek_dir); 
    void               skipwhite(); 
    int                sync(); 
    streampos          tellg(); 
    istream            &operator>>(char *); 
    istream            &operator>>(char &); 
    istream            &operator>>(short &); 
    istream            &operator>>(int &); 
    istream            &operator>>(long &); 
    istream            &operator>>(float &); 
    istream            &operator>>(double &); 
    istream            &operator>>(unsigned char *); 
    istream            &operator>>(unsigned char &); 
    istream            &operator>>(unsigned short &); 
    istream            &operator>>(unsigned int &); 
    istream            &operator>>(unsigned long &); 
    istream            &operator>>(streambuf *); 
    inline istream     &operator>>(istream &(*f)(istream &)); 
    istream            &operator>>(ios &(*f)(ios &)); 
 
protected: 
                       istream(); 
 
}; 


Description

This class provides facilities for formatted and unformatted extraction from streambuf objects.

Constructors and Destructors

istream(streambuf *sb)

Constructs an istream object. It initializes ios state variables and associates the istream object with the buffer pointed to by sb.

virtual ~istream()

Deletes an istream object.

Overloaded Operators

The following operators are all formatted input extractors. Given the expression ins >> x, these operators extract characters from ins and convert them to the variable x. The argument to the operator determines the type of x. Extractions are performed only if a call to ipfx(0) returns a nonzero value. Errors are indicated by setting the error state of ins. ios::failbit means that characters in ins did not represent the required type. ios::badbit means that attempts to extract characters failed. ins is always returned. The details of conversion depend on the values of the ins object format state flags and variables, and the type of x. Extractions that use width reset it to 0; otherwise, the extraction operators do not change the value of the istream object format state.

istream &operator >> (char &x)

istream &operator >> (unsigned char &x)

Extracts a character and stores it in x.

istream &operator >> (char *x)

istream &operator >> (unsigned char *x)

Extracts characters and stores them in the array pointed at by x, until a white-space character is found in the iostream object. The action leaves the terminating white-space character in the iostream object. If the iostream object's width() is nonzero, it is taken to be the size of the array and no more than width()--1 characters are extracted. A terminating null character ('\0') is always stored, even if nothing else is done because of the iostream object's error state. The iostream object's width() is reset to 0.

istream &operator >> (short &x)

istream &operator >> (int &x)

istream &operator >> (long &x)

istream &operator >> (unsigned short &x)

istream &operator >> (unsigned int &x)

istream &operator >> (unsigned long &x)

Extracts characters and converts them to an integral value according to the conversion specified in the iostream object's format flags. Converted values are stored in x. The first character can be a sign ( - or +). After that, the conversion is octal if ios::oct is set in the iostream object's flags, decimal if ios::dec is set, or hexadecimal if ios::hex is set.

The first nondigit that is left in the iostream object terminates the conversion. If no conversion base flag is set, the conversion proceeds according to C++ lexical conventions: if the first characters (after the optional sign) are 0x or 0X, the conversion is hexadecimal; if the first character is 0, the conversion is octal; otherwise, the conversion is decimal. If no digits are available (not counting the 0 in 0x or 0X during hex conversion), ios::failbit is set.

istream &operator >> (float &x)

istream &operator >> (double &x)

Extracts characters and converts them according to C++ syntax for a float value or a double value. Converted values are stored in x. If no digits are available in the iostream object, or if the iostream object does not begin with a well formed floating-point or double number, ios::failbit is set.

istream &operator >> (streambuf *b)

Keeps getting characters from ios and inserting them into the buffer b until EOF is reached, if ios::ipfx(0) returns nonzero. Always returns the iostream object.

istream &operator >> (ios &(*f)(ios &))

Calls an ios object manipulator function f for an istream object.

istream &operator >> (istream &(*f)(istream &))

Calls an istream object manipulator function f for an istream object.

Other Member Functions

The unformatted input extractors, get, getline, ignore, and read, are among these functions. Before performing any extractions, these extractors, plus the unformatted function peek (which returns the next character without extracting it), call ipfx(1) and proceed only if a nonzero value is returned.

int gcount()

Returns the number of characters extracted by the last unformatted input function (get, getline, ignore, and read). Note that formatted input functions can call unformatted input functions and also reset this number.

int get()

Extracts a character and returns it, or returns EOF if the extraction encounters the end-of-file. It never sets ios::failbit.

istream &get(char &ptr)

istream &get(unsigned char &ptr)

Extracts a single character and stores it in &ptr.

istream &get(char *ptr, int len, char delim)

istream &get(unsigned char *ptr, int len, char delim)

Extracts characters and stores them in the byte array beginning at ptr and extending for len bytes. Extraction stops when any of the following conditions are met:
  • The extractor encounters delim (delim is left in the istream object and not stored.)
  • The istream object has no more characters.
  • The array has only one byte left.

The function stores a terminating null, even if it does not extract any characters because of its error status. The extraction sets ios::failbit only if it reaches an end-of-file before storing any characters.

istream &get(streambuf &sb, char delim)

Extracts characters from an istream object rdbuf() function and stores them into sb. It stops if it encounters the end-of-file, if a store into sb fails, or if it encounters delim (which it leaves in the istream object). The function sets ios::failbit if the extraction stops because the store operation into sb fails.

istream &getline(char *ptr, int len, char delim)

istream &getline(unsigned char *ptr, int len, char delim)

Functions the same as get(char *, int, char) except that these extract a terminating delim character from an istream object. If delim occurs when exactly len characters have been extracted, a filled array is considered to be the cause of the termination and the extraction leaves this delim in the istream object.

istream &ignore(int len, int delim)

Extracts and discards up to len characters. Extraction stops prematurely if delim is extracted or the end-of-file is reached. If delim is EOF, it can never cause termination.

int ipfx(int need)

Returns 0 if the error state of an istream object is nonzero. If necessary (and if it is not null), the function flushes any ios tied to the istream object (see the description of ios::tie()). Flushing is considered necessary if need is set to 0 or if fewer than need characters are immediately available. If ios::skipws is set in the istream object's flags() function, and need is 0, then the function extracts the leading white-space characters from the istream object. The function returns 0 if an error occurs while skipping white space; otherwise, it returns a nonzero value.

void isfx()

Performs input suffix operations (used for internal processing).

int peek()

Begins by calling ipfx(1). If that call returns 0, or if the istream object is at the end-of-file, the function returns EOF. Otherwise, it returns the next character without extracting it.

istream &putback(char c)

Tries to back up an istream object rdbuf() function. c must be the character before the get pointer belonging to the istream object rdbuf(). (Unless some other activity is modifying the istream object rdbuf(), this is the last character extracted from the istream object.) If c is not the character before the get pointer, the effect of the function is undefined; the backup may fail and set the error state. The putback function is a member of the istream object, but it never extracts characters so it does not call ipfx. However, it returns without doing anything if the error state is nonzero.

istream &read(char *s, int n)

istream &read(unsigned char *s, int n)

Extracts n characters and stores them in the array begining at s. If it reaches the end-of-file before extracting n characters, the function stores whatever it can extract and sets ios::failbit. To determine the number of characters extracted, use the istream gcount() function.

istream &seekg(streampos)

istream &seekg(streamoff, seek_dir)

Repositions the get pointer of an istream object rdbuf() function.

int sync()

Establishes consistency between internal data structures and the external source of characters. Calls an istream object rdbuf()->sync(), which is a virtual function, so the details depend on the derived class. Returns EOF to indicate errors.

void skipwhite()

Skips extracted white-space characters.

streampos tellg()

Returns the current position of the get pointer of an istream object rdbuf() function.

Examples

#1

char c; 
cin.get(c); 
      

Extracts a single character from cin.

#2

tmp.seekg(10,ios::cur) 
      

Moves the point in a file from which information is read forward 10 bytes.


See Also

ios class
istream_withassign class
istrstream class

istream_withassign class

Adds an assignment operator and a constructor with no operands to the istream class.

Header File

#include <iostream.hxx>

Alternative Header

#include <iostream.h>


Declaration


class istream_withassign: public istream 
{ 
public: 
                        istream_withassign(); 
    virtual             ~istream_withassign(); 
 
    istream_withassign &operator=(istream &); 
    istream_withassign &operator=(streambuf *); 
}; 
 


Description

This class adds an assignment operator and a constructor with no operands to the istream class.

Constructors and Destructors

istream_withassign()

Constructs an istream_withassign object; it does no initialization.

virtual ~istream_withassign()

Deletes an istream_withassign object; no user action is required.

Overloaded Operators

istream_withassign &operator = (istream &s)

Associates an istream object's rdbuf() function with an istream_withassign object and initializes the entire state of that object.

istream_withassign &operator = (streambuf *sb)

Associates sb with an istream_withassign object and initializes the entire state of that object.

istrstream class

Specializes the istream class to perform extractions from arrays of bytes in memory.

Header File

#include <strstream.hxx>

Alternative Header

#include <strstream.h>


Declaration


class istrstream: public istream 
{ 
public: 
                        istrstream(char *); 
                        istrstream(char *, int); 
 
    strstreambuf        *rdbuf(); 
}; 


Description

Objects of this class perform in-core extractions from arrays of bytes in memory.

Constructors and Destructors

istrstream(char *cp)

Constructs an istrstream object and fetches characters from the (null terminated) string cp. The terminating null character does not become part of the sequence. Seeks (istream::seekg()) are permitted within the allocated space.

istrstream(char *cp, int len)

Constructs an istrstream object and fetches characters from the array beginning at cp and extending for len bytes. Seeks (istream::seekg()) are permitted anywhere within that array.

Member Function

strstreambuf *rdbuf()

Returns the strstreambuf object associated with the istrstream object.


Previous Next Contents Index

   
Burgundy bar
DIGITAL Home Feedback Search Sitemap Subscribe Help
Legal