다음을 통해 공유


basic_istringstream Class

 

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

Describes an object that controls extraction of elements and encoded objects from a stream buffer of class basic_stringbuf< Elem, Tr, Alloc>.

Syntax

template <class Elem, class Tr = char_traits<Elem>, class Alloc = allocator<Elem>>  
class basic_istringstream : public basic_istream<Elem, Tr>  

Parameters

Alloc
The allocator class.

Elem
The type of the basic element of the string.

Tr
The character traits specialized on the basic element of the string.

Remarks

The template class describes an object that controls extraction of elements and encoded objects from a stream buffer of class basic_stringbuf< Elem, Tr, Alloc>, with elements of type Elem, whose character traits are determined by the class Tr, and whose elements are allocated by an allocator of class Alloc. The object stores an object of class basic_stringbuf< Elem, Tr, Alloc>.

Constructors

basic_istringstream Constructs an object of type basic_istringstream.

Typedefs

allocator_type The type is a synonym for the template parameter Alloc.

Member Functions

rdbuf Returns the address of the stored stream buffer of type pointer to basic_stringbuf< Elem, Tr, Alloc>.
str Sets or gets the text in a string buffer without changing the write position.
swap Exchanges the values in this basic_istringstream object for those of the provided object.

Operators

operator= Assigns the values to this basic_istringstream object from the object parameter.

Requirements

Header: <sstream>

Namespace: std

basic_istringstream::allocator_type

The type is a synonym for the template parameter Alloc.

typedef Alloc allocator_type;  

basic_istringstream::basic_istringstream

Constructs an object of type basic_istringstream.

explicit basic_istringstream(
    ios_base::openmode _Mode = ios_base::in);

explicit basic_istringstream(
    const basic_string<Elem, Tr, Alloc>& str,  
    ios_base::openmode _Mode = ios_base::in);

basic_istringstream(
    basic_istringstream&& right);

Parameters

_Mode
One of the enumerations in ios_base::openmode.

str
An object of type basic_string.

right
An rvalue reference of a basic_istringstream object.

Remarks

The first constructor initializes the base class by calling basic_istream( sb), where sb is the stored object of class basic_stringbuf< Elem, Tr, Alloc>. It also initializes sb by calling basic_stringbuf< Elem, Tr, Alloc>( _Mode | ios_base::in).

The second constructor initializes the base class by calling basic_istream(sb). It also initializes sb by calling basic_stringbuf< Elem, Tr, Alloc>( str, _Mode | ios_base::in).

The third constructor initializes the object with the contents of right, treated as an rvalue reference.

basic_istringstream::operator=

Assigns the values to this basic_istringstream object from the object parameter.

basic_istringstream& operator=(basic_istringstream&& right);

Parameters

right
An rvalue reference to a basic_istringstream object.

Remarks

The member operator replaces the contents of the object with the contents of right, treated as an rvalue reference move assignment.

basic_istringstream::rdbuf

Returns the address of the stored stream buffer of type pointer to basic_stringbuf< Elem, Tr, Alloc>.

basic_stringbuf<Elem, Tr, Alloc> *rdbuf() const;

Return Value

The address of the stored stream buffer of type pointer to basic_stringbuf< Elem, Tr, Alloc>.

Example

See basic_filebuf::close for an example that uses rdbuf.

basic_istringstream::str

Sets or gets the text in a string buffer without changing the write position.

basic_string<Elem, Tr, Alloc> str() const;

 
void str(
    const basic_string<Elem, Tr, Alloc>& _Newstr);

Parameters

_Newstr
The new string.

Return Value

Returns an object of class basic_string< Elem, Tr, Alloc>, whose controlled sequence is a copy of the sequence controlled by *this.

Remarks

The first member function returns rdbuf -> str. The second member function calls rdbuf -> str( _Newstr).

Example

See basic_stringbuf::str for an example that uses str.

basic_istringstream::swap

Exchanges the values of two basic_istringstream objects.

void swap(basic_istringstream& right);

Parameters

Parameter Description
right An lvalue reference to a basic_istringstream object.

Remarks

The member function exchanges the values of this object and the values of right.

See Also

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