The GNU C++ Iostream Library



3.1.4: Advanced Features

The methods described on this page are not necessary for the normal use of the IO streams. Some of these topics are for class library writers.

  • Extending Extended data fields.
  • Synchronization Synchronizing related streams.
  • Streambuf from Ios Reaching the underlying streambuf.


  • 3.1.4.1: Extended data fields

    A related collection of methods allows you to extend this collection of flags and parameters for your own applications, without risk of conflict between them:


    Method:  static fmtflags ios::bitalloc ()

    Reserve a bit (the single bit on in the result) to use as a flag. Using bitalloc guards against conflict between two packages that use ios objects for different purposes.

    This method is available for upward compatibility, but is not in the ANSI working paper. The number of bits available is limited; a return value of 0 means no bit is available.


    Method:  static int ios::xalloc ()

    Reserve space for a long integer or pointer parameter. The result is a unique nonnegative integer. You can use it as an index to ios::iword or ios::pword. Use xalloc to arrange for arbitrary special-purpose data in your ios objects, without risk of conflict between packages designed for different purposes.

    Method:  long& ios::iword (int index)

    Return a reference to arbitrary data, of long integer type, stored in an ios instance. index, conventionally returned from ios::xalloc, identifies what particular data you need.

    Method:  long ios::iword (int index) const

    Return the actual value of a long integer stored in an ios.

    Method:  void*& ios::pword (int index)

    Return a reference to an arbitrary pointer, stored in an ios instance. index, originally returned from ios::xalloc, identifies what particular pointer you need.

    Method:  void* ios::pword (int index) const

    Return the actual value of a pointer stored in an ios.


    3.1.4.2: Synchronizing related streams

    You can use these methods to synchronize related streams with one another:


    Method:  ostream* ios::tie () const

    Report on what output stream, if any, is to be flushed before accessing this one. A pointer value of 0 means no stream is tied.

    Method:  ostream* ios::tie (ostream* assoc)

    Declare that output stream assoc must be flushed before accessing this stream.

    Method:  int ios::sync_with_stdio ([int switch])

    Unless iostreams and C stdio are designed to work together, you may have to choose between efficient C++ streams output and output compatible with C stdio. Use `ios::sync_with_stdio()' to select C compatibility.

    The argument switch is a GNU extension; use 0 as the argument to choose output that is not necessarily compatible with C stdio. The default value for switch is 1.

    If you install the stdio implementation that comes with GNU libio, there are compatible input/output facilities for both C and C++. In that situation, this method is unnecessary---but you may still want to write programs that call it, for portability.


    3.1.4.3: Reaching the underlying streambuf

    Finally, you can use this method to access the underlying object:


    Method:  streambuf* ios::rdbuf () const

    Return a pointer to the streambuf object that underlies this ios.


    Translated 02/24/96 by Rance Necaise. Original texi file by Bothner and Pesch.