Go to main content
Oracle Developer Studio 12.5 Man Pages

Exit Print View

Updated: June 2017
 
 

stdiobuf(3CC4)

Name

stdiobuf - buffer and stream classes for use with C stdio

Synopsis

 
#include <stdiostream.h> // includes <iostream.h> and <stdio.h>
class stdiobuf : public streambuf {
public:
     stdiobuf(FILE*);
     FILE*     stdiofile();
};
class stdiostream : public ios {
public:
     stdiostream(FILE*);
     stdiobuf* rdbuf();
};

Description

The stdiobuf class is a specialization of streambufs using a C stdio FILE as an intermediary to an actual file which is the source or destination of characters. The basic streambuf operations are as described in sbufprot(3CC4) and sbufpub(3CC4). Input, output, and seek operations are reflected in changes to the associated FILE. The seek functions are implemented in terms of fseek(), for example.

The stdiostream provides a C++ interface to a C stdio FILE. It has a stdiobuf as its buffer. It is not a full implementation of iostreams; it has only the buffer-class and ios-class functionality. C++ I/O is done via per-character calls to the C stdio getc() and putc() functions. There is no normal buffering, since that would break synchronization of the C and C++ accesses.

The only reason to use either of these classes is to provide a way to mix C stdio code and C++ iostream-like code on the same file. Prefer to use filebuf and fstream, which are far more efficient, for new code.

stdiobuf functions

stdiobuf(fp)

Constructs a stdiobuf attached to the FILE structure pointed to by fp.

FILE* fp = siobuf.stdiofile()

Returns a pointer to the FILE structure associated with siobuf.

stdiostream functions

stdiostream(fp)

Constructs a stdiostream attached to the FILE structure pointed to by fp.

stdiobuf* sbp = siostr.rdbuf()

Returns a pointer to the stdiobuf associated with siostr. This is the same as ios::rdbuf(), except that the return type is specifically a stdiobuf.

See Also

ios (3CC4) , ios.intro (3CC4) , sbufprot (3CC4) , sbufpub (3CC4) , stdio (3C)

C++ Library Reference, Chapter 3, "The Classic iostream Library"