The ANSIISO Standard IO Functions

Several Data Types

In addition to the fmtflags type just described, the Standard C++ I/O system defines several other types.

The streamsize and streamoff Types

An object of type streamsize is capable of holding the largest number of bytes that will be transferred in any one I/O operation. It is typically some form of integer. An object of type streamoff is capable of holding a value that indicates an offset position within a stream. It is typically some form of integer. These types are defined in the header <ios>, which is automatically included by the I/O system.

The streampos and wstreampos Types

An object of type streampos is capable of holding a value that represents a position within a char stream. The wstreampos type is capable of holding a value that represents a position within a wchar_t stream. These are defined by in <iosfwd>, which is automatically included by the I/O system.

The pos_type and off_type Types

The types pos_type and off_type create objects (typically integers) that are capable of holding a value that represents the position and an offset, respectively, within a stream. These types are defined by ios (and other classes) and are essentially the same as streamoff and streampos (or their wide-character equivalents).

The openmode Type

The type openmode is defined by ios_base and describes how a file will be opened. It will be one or more of these values:

app

Append to end of file

ate

Seek to end of file on creation

binary

Open file for binary operations

in

Open file for input

out

Open file for output

trunc

Erase previously existing file

You can combine two or more of these values by ORing them together.

The iostate Type

The current status of an I/O stream is described by an object of type iostate, which is an enumeration defined by ios_base that includes these members:

Name

Meaning

goodbit

No errors occurred

eofbit

End of file is encountered

failbit

A nonfatal I/O error has occurred

badbit

A fatal I/O error has occurred

The seekdir type

The seekdir type describes how a random-access file operation will take place. It is defined within ios_base. Its valid values are shown here:

beg

Beginning of file

cur

Current location

end

End of file

The failure Class

In ios_base is defined the exception type failure. It serves as a base class for the types of exceptions that can be thrown by the I/O system. It inherits exception (the standard exception class). The failure class has the following constructor:

explicit failure(const string &str);

Here, str is a message that describes the error. This message can be obtained from a failure object by calling its what( ) function, shown here:

virtual const char *what( ) const throw( );




C(s)C++ Programmer's Reference
C Programming on the IBM PC (C Programmers Reference Guide Series)
ISBN: 0673462897
EAN: 2147483647
Year: 2002
Pages: 539

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net