Compartir a través de


strstream Class

 

The latest version of this topic can be found at strstream Class.

Describes an object that controls insertion and extraction of elements and encoded objects using a stream buffer of class strstreambuf.

Syntax

class strstream : public iostream

Remarks

The object stores an object of class strstreambuf.

Note

This class is deprecated. Consider using stringstream or wstringstream instead.

Constructors

strstream Constructs an object of type strstream.

Member Functions

freeze Causes a stream buffer to be unavailable through stream buffer operations.
pcount Returns a count of the number of elements written to the controlled sequence.
rdbuf Returns a pointer to the stream's associated strstreambuf object.
str Calls freeze, and then returns a pointer to the beginning of the controlled sequence.

Requirements

Header: <strstream>

Namespace: std

strstream::freeze

Causes a stream buffer to be unavailable through stream buffer operations.

void freeze(bool _Freezeit = true);

Parameters

_Freezeit
A bool indicating whether you want the stream to be frozen.

Remarks

The member function calls rdbuf -> freeze(_ Freezeit).

Example

See strstreambuf::freeze for an example that uses freeze.

strstream::pcount

Returns a count of the number of elements written to the controlled sequence.

streamsize pcount() const;

Return Value

The number of elements written to the controlled sequence.

Remarks

The member function returns rdbuf -> pcount.

Example

See strstreambuf::pcount for a sample of using pcount.

strstream::rdbuf

Returns a pointer to the stream's associated strstreambuf object.

strstreambuf *rdbuf
() const

Return Value

A pointer to the stream's associated strstreambuf object.

Remarks

The member function returns the address of the stored stream buffer of type pointer to strstreambuf.

Example

See strstreambuf::pcount for a sample that uses rdbuf.

strstream::str

Calls freeze, and then returns a pointer to the beginning of the controlled sequence.

char *str();

Return Value

A pointer to the beginning of the controlled sequence.

Remarks

The member function returns rdbuf -> str.

Example

See strstreambuf::str for a sample that uses str.

strstream::strstream

Constructs an object of type strstream.

strstream();

strstream(char* ptr,
    streamsize count,
    ios_base::openmode _Mode = ios_base::in | ios_base::out);

Parameters

count
The size of the buffer.

_Mode
The input and output mode of the buffer. See ios_base::openmode for more information.

ptr
The buffer.

Remarks

Both constructors initialize the base class by calling streambuf( sb), where sb is the stored object of class strstreambuf. The first constructor also initializes sb by calling strstreambuf. The second constructor initializes the base class one of two ways:

  • If _Mode & ios_base::app== 0, then ptr must designate the first element of an array of count elements, and the constructor calls strstreambuf( ptr, count, ptr).

  • Otherwise, ptr must designate the first element of an array of count elements that contains a C string whose first element is designated by ptr, and the constructor calls strstreambuf( ptr, count, ptr + strlen( ptr) ).

See Also

iostream
Thread Safety in the C++ Standard Library
iostream Programming
iostreams Conventions