Overview
basic_stringstream class is designed to read from and write to memory stream.
Details
The class template basic_stringstream provides support for high level input and output operations on memory streams. The supported operations include formatted input and output (e.g. integer values or whitespace-separated characters and characters strings) and unformatted input and output(e.g. raw characters and character arrays).
basic_stringstream class is basically derived class of basic_istringstream and basic_ostringstream. It has no additional functionality other than constructor.
Syntax
template<class CharT, class Traits = char_traits<CharT>>class basic_stringstream: public basic_iostream<CharT,Traits>
where CharT can be char or wchar_t. It's derived from basic_ios class.
member types
Following properties are defined.
Name | Definition |
---|---|
char_type | char,wchar_t |
traits_type | char_traits<char_type> |
int_type | char_traits<char_type>::int_type |
pos_type | char_traits<char_type>::pos_type |
off_type | char_traits<char_type>::off_type |
The openmode flags indicate how the streams such as disk files or memory streams can be opened for IO operations such as read, write or append.
Constructor
Name | Description |
---|---|
|
The mode constants are defined in ios_base class.
|
Methods
Name Description basic_streambuf* rdbuf() Returns pointer to the underlying raw file device object.
Exampleistringstream s {"hello, world!"};
auto sb = s.rdbuf();
- void str
(const basic_string& s)- basic_string str()
- Sets the current contents of the stream to s
- Returns the current contents of the stream as string.
Exampleistringstream ss,ss2; ss.str("hello, world!"); ss2.str(ss.str());
No comments:
Post a Comment