basic_istringstream , basic_ostringstream , basic_stringbuf , basic_stringstream , istringstream , ostringstream , stringbuf , stringstream , wistringstream , wostringstream , wstringbuf , wstringstream - defines several iostreams template classes that manipulate string containers
namespace std { template<class E, class T = char_traits<E>, class A = allocator<E> > class basic_stringbuf; typedef basic_stringbuf<char> stringbuf; typedef basic_stringbuf<wchar_t> wstringbuf; template<class E, class T = char_traits<E>, class A = allocator<E> > class basic_istringstream; typedef basic_istringstream<char> istringstream; typedef basic_istringstream<wchar_t> wistringstream; template<class E, class T = char_traits<E>, class A = allocator<E> > class basic_ostringstream; typedef basic_ostringstream<char> ostringstream; typedef basic_ostringstream<wchar_t> wostringstream; template<class E, class T = char_traits<E>, class A = allocator<E> > class basic_stringstream; typedef basic_stringstream<char> stringstream; typedef basic_stringstream<wchar_t> wstringstream; };
Include the iostreams
standard header <sstream>
to define several template classes that support
iostreams operations on
sequences stored in an allocated array object.
Such sequences are easily converted to and from objects of
template class
basic_string
.
basic_stringbuf , overflow , pbackfail , seekoff , seekpos , str , underflow
template <class E, class T = char_traits<E>, class A = allocator<E> > class basic_stringbuf : public basic_streambuf<E, T> { public: typedef typename basic_streambuf<E, T>::char_type char_type; typedef typename basic_streambuf<E, T>::traits_type traits_type; typedef typename basic_streambuf<E, T>::int_type int_type; typedef typename basic_streambuf<E, T>::pos_type pos_type; typedef typename basic_streambuf<E, T>::off_type off_type; basic_stringbuf(ios_base::openmode mode = ios_base::in | ios_base::out); basic_stringbuf(basic_string<E, T, A>& x, ios_base::openmode mode = ios_base::in | ios_base::out); basic_string<E, T, A> str() const; void str(basic_string<E, T, A>& x); protected: virtual pos_type seekoff(off_type off, ios_base::seekdir way, ios_base::openmode mode = ios_base::in | ios_base::out); virtual pos_type seekpos(pos_type sp, ios_base::openmode mode = ios_base::in | ios_base::out); virtual int_type underflow(); virtual int_type pbackfail(int_type c = traits_type::eof()); virtual int_type overflow(int_type c = traits_type::eof()); };
The template class
describes a stream buffer that controls
the transmission of elements
of type E
, whose
character traits are determined by the
class T
,
to and from a sequence of elements
stored in an array object. The object is allocated, extended, and
freed as necessary to accommodate changes in the sequence.
An object of class
basic_stringbuf<E, T, A>
stores a copy of the
ios_base::openmode
argument from its constructor as its
stringbuf mode mode
:
mode &
ios_base::in
is nonzero,
the input buffer
is accessible.mode &
ios_base::out
is nonzero,
the output buffer
is accessible.basic_stringbuf(ios_base::openmode mode = ios_base::in | ios_base::out); basic_stringbuf(basic_string<E, T, A>& x, ios_base::openmode mode = ios_base::in | ios_base::out);
The first constructor stores a null pointer in all the pointers
controlling the
input buffer and the
output buffer. It
also stores mode
as the
stringbuf mode.
The second constructor allocates a copy of the sequence controlled
by the string object x
.
If mode & ios_base::in
is nonzero,
it sets the input buffer to begin reading
at the start of the sequence.
If mode & ios_base::out
is nonzero,
it sets the output buffer to begin
writing at the start of the sequence.
It also stores mode
as the
stringbuf mode.
typedef E char_type;
The type is a synonym for the template parameter E
.
typedef typename traits_type::int_type int_type;
The type is a synonym for
traits_type::int_type
.
typedef typename traits_type::off_type off_type;
The type is a synonym for
traits_type::off_type
.
virtual int_type overflow(int_type c = traits_type::eof());
If c
does not compare equal to
traits_type::eof()
,
the protected virtual member function endeavors to insert the element
traits_type::to_char_type(c)
into the
output buffer.
It can do so in various ways:
If the function cannot succeed, it returns traits_type::eof()
.
Otherwise, it returns
traits_type::not_eof(c)
.
virtual int_type pbackfail(int_type c = traits_type::eof());
The protected virtual member function endeavors to put back an element
into the
input buffer,
then make it the current element (pointed to
by the next pointer).
If c
compares equal to
traits_type::eof()
,
the element to push back is effectively the one already in the stream
before the current element. Otherwise, that element is replaced by
x =
traits_type::to_char_type(c)
.
The function can put back an element in various ways:
x
,
it can simply decrement the next pointer for the input buffer.mode &
ios_base::out
is nonzero),
it can store x
into the putback position and decrement the
next pointer for the input buffer.If the function cannot succeed, it returns
traits_type::eof()
. Otherwise, it returns
traits_type::not_eof(c)
.
typedef typename traits_type::pos_type pos_type;
The type is a synonym for
traits_type::pos_type
.
virtual pos_type seekoff(off_type off, ios_base::seekdir way, ios_base::openmode mode = ios_base::in | ios_base::out);
The protected virtual member function endeavors to alter the current
positions for the controlled streams. For an object of class
basic_stringbuf<E, T, A>
,
a stream position consists
purely of a stream offset. Offset zero designates the first element
of the controlled sequence.
The new position is determined as follows:
way ==
ios_base::beg
,
the new position is the beginning of the stream plus off
.
way ==
ios_base::cur
,
the new position is the current stream position plus off
.
way ==
ios_base::end
,
the new position is the end of the stream plus off
.
If
mode & ios_base::in
is nonzero,
the function alters the next position to read in the
input buffer.
If mode & ios_base::out
is nonzero,
the function alters the next position to write in the
output buffer.
For a stream to be affected, its buffer must exist.
For a positioning operation to succeed, the resulting
stream position must lie within the controlled sequence.
If the function affects both stream positions, way
must be ios_base::beg
or ios_base::end
and both streams are positioned at the same element.
Otherwise (or if neither position is affected) the positioning
operation fails.
If the function succeeds in altering the stream position(s), it returns the resultant stream position. Otherwise, it fails and returns an invalid stream position.
virtual pos_type seekpos(pos_type sp, ios_base::openmode mode = ios_base::in | ios_base::out);
The protected virtual member function endeavors to alter the current
positions for the controlled streams. For an object of class
basic_stringbuf<E, T, A>
,
a stream position consists
purely of a stream offset. Offset zero designates the first element
of the controlled sequence. The new position is determined
by sp
.
If
mode & ios_base::in
is nonzero,
the function alters the next position to read in the
input buffer.
If mode & ios_base::out
is nonzero,
the function alters the next position to write in the
output buffer.
For a stream to be affected, its buffer must exist.
For a positioning operation to succeed, the resulting
stream position must lie within the controlled sequence.
Otherwise (or if neither position is affected) the positioning
operation fails.
If the function succeeds in altering the stream position(s), it returns the resultant stream position. Otherwise, it fails and returns an invalid stream position.
basic_string<E, T, A> str() const; void str(basic_string<E, T, A>& x);
The first member function returns an object of class
basic_string<E, T, A>
,
whose controlled sequence is a copy of the sequence controlled
by *this
. The sequence copied depends on the stored
stringbuf mode mode
:
mode &
ios_base::out
is nonzero
and an output buffer exists,
the sequence is the entire output buffer
(epptr() -
pbase()
elements beginning with pbase()
).mode &
ios_base::in
is nonzero
and an input buffer exists,
the sequence is the entire input buffer
(egptr() -
eback()
elements beginning with eback()
).The second member function deallocates any sequence currently
controlled by *this
. It then
allocates a copy of the sequence controlled
by x
. If mode & ios_base::in
is nonzero,
it sets the input buffer to begin reading
at the beginning of the sequence.
If mode & ios_base::out
is nonzero,
it sets the output buffer to begin
writing at the beginning of the sequence.
typedef T traits_type;
The type is a synonym for the template parameter T
.
virtual int_type underflow();
The protected virtual member function endeavors to extract the current
element c
from the
input buffer,
then advance the current stream position, and return the element as
traits_type::to_int_type(c)
.
It can do so in only one way:
If a read position
is available, it takes c
as the element stored
in the read position and advances the next pointer for the input buffer.
If the function cannot succeed, it returns
traits_type::eof()
. Otherwise,
it returns the current element in the input stream,
converted as described above.
basic_istringstream , rdbuf , str
template <class E, class T = char_traits<E>, class A = allocator<E> > class basic_istringstream : public basic_istream<E, T> { public: explicit basic_istringstream( ios_base::openmode mode = ios_base::in); explicit basic_istringstream( const basic_string<E, T, A>& x, ios_base::openmode mode = ios_base::in); basic_stringbuf<E, T, A> *rdbuf() const; basic_string<E, T, A>& str(); void str(const basic_string<E, T, A>& x); };
The template class describes an object that controls
extraction of elements and encoded objects from a
stream buffer of class
basic_stringbuf<E, T, A>
,
with elements of type E
, whose
character traits are determined
by the class T
, and whose elements are allocated by
an allocator of class A
. The object stores an object of class
basic_stringbuf<E, T, A>
.
explicit basic_istringstream( ios_base::openmode mode = ios_base::in); explicit basic_istringstream( const basic_string<E, T, A>& x, ios_base::openmode mode = ios_base::in);
The first constructor initializes the base class by calling
basic_istream(sb)
,
where sb
is the stored object of class
basic_stringbuf<E, T, A>
.
It also initializes sb
by calling
basic_stringbuf<E,
T, A>(mode | ios_base::in)
.
The second constructor initializes the base class by calling
basic_istream(sb)
.
It also initializes sb
by calling
basic_stringbuf<E,
T, A>(x, mode | ios_base::in)
.
basic_stringbuf<E, T, A> *rdbuf() const
The member function returns the address of the stored
stream buffer, of type pointer to
basic_stringbuf<E,
T, A>
.
basic_string<E, T, A> str() const; void str(basic_string<E, T, A>& x);
The first member function returns
rdbuf()->
str()
.
The second member function calls rdbuf()-> str(x)
.
basic_ostringstream , rdbuf , str
template <class E, class T = char_traits<E>, class A = allocator<E> > class basic_ostringstream : public basic_ostream<E, T> { public: explicit basic_ostringstream( ios_base::openmode mode = ios_base::out); explicit basic_ostringstream( const basic_string<E, T, A>& x, ios_base::openmode mode = ios_base::out); basic_stringbuf<E, T, A> *rdbuf() const; basic_string<E, T, A>& str(); void str(const basic_string<E, T, A>& x); };
The template class describes an object that controls
insertion of elements and encoded objects into a
stream buffer of class
basic_stringbuf<E, T, A>
,
with elements of type E
, whose
character traits are determined
by the class T
, and whose elements are allocated by
an allocator of class A
. The object stores an object of class
basic_stringbuf<E, T, A>
.
explicit basic_ostringstream( ios_base::openmode mode = ios_base::out); explicit basic_ostringstream( const basic_string<E, T, A>& x, ios_base::openmode mode = ios_base::out);
The first constructor initializes the base class by calling
basic_ostream(sb)
,
where sb
is the stored object of class
basic_stringbuf<E, T, A>
.
It also initializes sb
by calling
basic_stringbuf<E,
T, A>(mode | ios_base::out)
.
The second constructor initializes the base class by calling
basic_ostream(sb)
.
It also initializes sb
by calling
basic_stringbuf<E,
T, A>(x, mode | ios_base::out)
.
basic_stringbuf<E, T, A> *rdbuf() const
The member function returns the address of the stored
stream buffer, of type pointer to
basic_stringbuf<E,
T, A>
.
basic_string<E, T, A> str() const; void str(basic_string<E, T, A>& x);
The first member function returns
rdbuf()->
str()
.
The second member function calls rdbuf()-> str(x)
.
basic_stringstream , rdbuf , str
template <class E, class T = char_traits<E>, class A = allocator<E> > class basic_stringstream : public basic_iostream<E, T> { public: explicit basic_stringstream( ios_base::openmode mode = ios_base::in | ios_base::out); explicit basic_stringstream( const basic_string<E, T, A>& x, ios_base::openmode mode = ios_base::in | ios_base::out); basic_stringbuf<E, T, A> *rdbuf() const; basic_string<E, T, A>& str(); void str(const basic_string<E, T, A>& x); };
The template class describes an object that controls
insertion and extraction of elements and encoded objects using a
stream buffer of class
basic_stringbuf<E, T, A>
,
with elements of type E
, whose
character traits are determined
by the class T
, and whose elements are allocated by
an allocator of class A
. The object stores an object of class
basic_stringbuf<E, T, A>
.
explicit basic_stringstream( ios_base::openmode mode = ios_base::in | ios_base::out); explicit basic_stringstream( const basic_string<E, T, A>& x, ios_base::openmode mode = ios_base::in | ios_base::out);
The first constructor initializes the base class by calling
basic_iostream(sb)
,
where sb
is the stored object of class
basic_stringbuf<E, T, A>
.
It also initializes sb
by calling
basic_stringbuf<E,
T, A>(mode)
.
The second constructor initializes the base class by calling
basic_ostream(sb)
.
It also initializes sb
by calling
basic_stringbuf<E,
T, A>(x, mode)
.
basic_stringbuf<E, T, A> *rdbuf() const
The member function returns the address of the stored
stream buffer, of type pointer to
basic_stringbuf<E,
T, A>
.
basic_string<E, T, A> str() const; void str(basic_string<E, T, A>& x);
The first member function returns
rdbuf()->
str()
.
The second member function calls rdbuf()-> str(x)
.
typedef basic_istringstream<char> istringstream;
The type is a synonym for template class
basic_istringstream
, specialized
for elements of type char.
typedef basic_ostringstream<char> ostringstream;
The type is a synonym for template class
basic_ostringstream
, specialized
for elements of type char.
typedef basic_stringbuf<char> stringbuf;
The type is a synonym for template class
basic_stringbuf
, specialized
for elements of type char.
typedef basic_stringstream<char> stringstream;
The type is a synonym for template class
basic_stringstream
, specialized
for elements of type char.
typedef basic_istringstream<wchar_t> wistringstream;
The type is a synonym for template class
basic_istringstream
, specialized
for elements of type wchar_t
.
typedef basic_ostringstream<wchar_t> wostringstream;
The type is a synonym for template class
basic_ostringstream
, specialized
for elements of type wchar_t
.
typedef basic_stringbuf<wchar_t> wstringbuf;
The type is a synonym for template class
basic_stringbuf
, specialized
for elements of type wchar_t
.
typedef basic_stringstream<wchar_t> wstringstream;
The type is a synonym for template class
basic_stringstream
, specialized
for elements of type wchar_t
.
Copyright © 1992-1996 by P.J. Plauger. Portions derived from work copyright © 1994 by Hewlett-Packard Company. All rights reserved.