Overview
basic_stringbuf is a template based class used for read from or/and write to strings in the memory.
Details
istringstream, ostringstream and stringstream classes uses a basic_stringbuf to read from or/and write to strings. It's derived from basic_streambuf class.
Syntax
template<class CharT, class Traits = char_traits<CharT>, class Alloc = allocator<CharT>>class basic_stringbuf:public basic_streambuf<CharT,Traits>
where CharT can be char or wchar_t.
PropertiesFollowing properties are defined.
Name Definition char_type char,wchar_t traits_type char_traits<char_type> allocator_type allocate<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 openmodeThe 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. These are used in calls such as fopen(). These are bitmask type flags that can be ORed. The following describes different values.
Name Description in Open file for reading. out Open file for writing. ate Set the stream's position indicator to the end of the stream on opening. app Set the stream's position indicator to the end of the stream before each output operation. trunc Any current content is discarded, assuming a length of zero on opening. binary Consider stream as binary rather than text. Note it's possible to have multiple flags set. i.e., in | out set at the same time.Note that in case of ate, writes can be on done anywhere in the stream. For example, begin or middle. In case of app, writes can be done only in the end.Note that difference between text and binary files is that in a text file individual lines are demarcated by a newline character \n or \r\n. In case of binary files there are no such demarcation.Constructor
Name Description
- basic_istringbuf
(ios_base::openmode mode = ios_base::in | ios_base::out)- basic_istringbuf
(const basic_string& s,
ios_base::openmode mode = ios_base::in | ios_base::out)
- Constructs an empty basic_stringbuf object.
- Constructs basic_stringbuf object with the content from s.
The mode constants are defined in ios_base class.Examplestringbuf s, s2 {"hello, world!"};
MethodsThese are the public functions available for the clients like istringstream, ostringstream and stringstream classes.
Name Description
- 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.
Examplestringbuf ss,ss2; ss.str("hello, world!"); ss2.str(ss.str());
No comments:
Post a Comment