sync_with_stdio

strstream, istrstream, and ostrstream

#include <strstrea.h>strstream();strstream(char *buf, int size, int mode); istrstream(const char *buf); istrstream(const char *buf, int size); ostrstream(); ostrstream(char *buf, int size, int mode=ios::out) 

The strstream( ) constructor is a member of strstream, the istrstream( ) constructor is a member of istrstream, and the ostrstream( ) constructor is a member of ostrstream.

These constructors are used to create array-based streams that support C++’s array-based I/O functions.

For ostrstream( ), buf is a pointer to the array that collects characters written to the stream. The size of the array is passed in the size parameter. By default, the stream is opened for normal output, but you can specify a different mode using the mode parameter. The legal values for mode are the same as those used with open( ). For most purposes, mode will be allowed to default. If you use the parameterless version of ostrstream( ), a dynamic array is automatically allocated.

For the single-parameter version of istrstream( ), buf is a pointer to the array that will be used as a source of characters each time input is performed on the stream. The contents of the array pointed to by buf must be null terminated. However, the null terminator is never read from the array.

If you wish only part of a string to be used for input, use the two-parameter form of the istrstream( ) constructor. Here, only the first size elements of the array pointed to by buf will be used. This string need not be null terminated, since it is the value of size that determines the size of the string.

To create an array-based stream capable of input and output, use strstream( ). In the parameterized version, buf points to the string that will be used for I/O operations. The value of size specifies the size of the array. The value of mode determines how the stream operates. For normal input/output operations, mode will be ios::in | ios::out. For input, the array must be null terminated.

If you use the parameterless version of strstream( ), the buffer used for I/O will be dynamically allocated, and the mode is set for read/write operations.

Related functions are str( ) and open( ).




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