Defined in the header file <sstream>
template< class CharT, |
std::basic_stringbuf
is a std::basic_streambuf whose associated character sequence is an arbitrary character sequence that is memory-resident. It can be initialized from an instance of std::basic_string, or made an instance of that class.
std::basic_stringbuf
A typical implementation keeps an object of type std::basic_string , or an equivalent scalable sequence container, as a data member, and uses it as both a sequence of controlled characters (an array of six pointers to std::basic_streambuf ) and Associated character sequence (character source for all input operations and target for output operations).
In addition, typical implementations keep a data member of type std::ios_base::openmode to indicate the state of the stream (read-only, write-only, read-write, end-write, etc.).
If overflow() uses an allocation strategy, an additional high-water mark pointer may be stored to keep track of the last initialized character. | (since C++11) |
Two specializations for common character types are also provided:
type | definition |
stringbuf |
basic_stringbuf<char> |
wstringbuf |
basic_stringbuf<wchar_t> |
member type
member type | definition |
char_type |
CharT |
traits_type |
Traits ; if Traits::char_type not CharT the program is ill-formed. |
int_type |
Traits::int_type |
pos_type |
Traits::pos_type |
off_type |
Traits::off_type |
allocator_type |
Allocator (since C++11) |
member function
public member function |
|
(Constructor) |
Construct a basic_stringbuf object (public member function) |
operator= (C++11) |
Assign basic_stringbuf object (public member function) |
swap (C++11) |
Exchange two basic_stringbuf objects (public member function) |
(destructor) [virtual] (implicit declaration) |
Destruct the basic_stringbuf object and its held string (virtual public member function) |
str |
replace or get a copy of the associated string (public member function) |
protected member function |
|
underflow [virtual] |
Returns the next character available in the input sequence (virtual protected member function) |
pbackfail [virtual] |
Play back characters into the output sequence (virtual protected member function) |
overflow [virtual] |
Append character to output sequence (virtual protected member function) |
setbuf [virtual] |
attempt to replace a controlled character sequence with an array (virtual protected member function) |
seekoff [virtual] |
Relocates the next position pointer in the input sequence, the output sequence, or both using relative addressing (virtual protected member function) |
seekpos [virtual] |
Using absolute addressing, relocates the next location pointer in the input sequence, the output sequence, or both (virtual protected member function) |
non-member function
std::swap(std::basic_stringbuf) (C++11) |
specialization of the std::swap algorithm (function template) |
Inherited from std::basic_streambuf
member type
member type | definition |
char_type |
CharT |
traits_type |
Traits ; if Traits::char_type not CharT the program is ill-formed. |
int_type |
Traits::int_type |
pos_type |
Traits::pos_type |
off_type |
Traits::off_type |
成员函数
(析构函数) [虚] |
析构 basic_streambuf 对象 ( std::basic_streambuf<CharT,Traits> 的虚公开成员函数) |
本地环境 |
|
pubimbue |
调用 imbue() ( std::basic_streambuf<CharT,Traits> 的公开成员函数) |
getloc |
获得相关本地环境的副本 ( std::basic_streambuf<CharT,Traits> 的公开成员函数) |
寻位 |
|
pubsetbuf |
调用 setbuf() ( std::basic_streambuf<CharT,Traits> 的公开成员函数) |
pubseekoff |
调用 seekoff() ( std::basic_streambuf<CharT,Traits> 的公开成员函数) |
pubseekpos |
调用 seekpos() ( std::basic_streambuf<CharT,Traits> 的公开成员函数) |
pubsync |
调用 sync() ( std::basic_streambuf<CharT,Traits> 的公开成员函数) |
获取区 |
|
in_avail |
获得获取区中立即可用的字符数 ( std::basic_streambuf<CharT,Traits> 的公开成员函数) |
snextc |
令输入序列前进,读取一个字符而不再次前进 ( std::basic_streambuf<CharT,Traits> 的公开成员函数) |
sbumpc |
从输入序列读取一个字符并令序列前进 ( std::basic_streambuf<CharT,Traits> 的公开成员函数) |
stossc (C++98 中弃用)(C++17 中移除) |
令输入序列前进,如同通过调用 sbumpc() 并舍弃结果 (公开成员函数) |
sgetc |
从输入序列读取一个字符,而不令序列前进 ( std::basic_streambuf<CharT,Traits> 的公开成员函数) |
sgetn |
调用 xsgetn() ( std::basic_streambuf<CharT,Traits> 的公开成员函数) |
放置区 |
|
sputc |
写一个字符到放置区域,并令 next 指针前进 ( std::basic_streambuf<CharT,Traits> 的公开成员函数) |
sputn |
调用 xsputn() ( std::basic_streambuf<CharT,Traits> 的公开成员函数) |
回放 |
|
sputbackc |
在输入序列中放回一个字符 ( std::basic_streambuf<CharT,Traits> 的公开成员函数) |
sungetc |
回移一位输出序列中的下一位置指针 ( std::basic_streambuf<CharT,Traits> 的公开成员函数) |
受保护成员函数
(构造函数) |
构造 basic_streambuf 对象 (受保护成员函数) |
operator= (C++11) |
替换 basic_streambuf 对象 (受保护成员函数) |
swap (C++11) |
交换二个 basic_streambuf 对象 (受保护成员函数) |
本地环境 |
|
imbue [虚] |
更改关联的本地环境 ( std::basic_streambuf<CharT,Traits> 的虚受保护成员函数) |
寻位 |
|
setbuf [虚] |
若容许则以用户定义数组替换缓冲区 ( std::basic_streambuf<CharT,Traits> 的虚受保护成员函数) |
seekoff [虚] |
用相对寻址重定位输入序列、输出序列或两者中的下一位置指针 ( std::basic_streambuf<CharT,Traits> 的虚受保护成员函数) |
seekpos [虚] |
用绝对寻址重定位输入序列、输出序列或两者中的下一位置指针 ( std::basic_streambuf<CharT,Traits> 的虚受保护成员函数) |
sync [虚] |
将缓冲与关联的字符序列同步 ( std::basic_streambuf<CharT,Traits> 的虚受保护成员函数) |
获取区 |
|
showmanyc [虚] |
若已知,则获得关联输入序列中可用于输入的字符数 ( std::basic_streambuf<CharT,Traits> 的虚受保护成员函数) |
underflow [虚] |
从关联输入序列读取字符到获取区 ( std::basic_streambuf<CharT,Traits> 的虚受保护成员函数) |
uflow [虚] |
从输入序列读取字符到获取区,并令下一位置指针前进 ( std::basic_streambuf<CharT,Traits> 的虚受保护成员函数) |
xsgetn [虚] |
从输入序列读取多个字符 ( std::basic_streambuf<CharT,Traits> 的虚受保护成员函数) |
ebackgptregptr |
返回指向获取区起始、当前字符和末尾的指针 (受保护成员函数) |
gbump |
令输出序列中的下一位置指针前进 (受保护成员函数) |
setg |
重定位输出序列的起始、下一位置和终止指针 (受保护成员函数) |
放置区 |
|
xsputn [虚] |
将多个字符写到输出序列 ( std::basic_streambuf<CharT,Traits> 的虚受保护成员函数) |
overflow [虚] |
从放置区写入字符到关联的输出序列 ( std::basic_streambuf<CharT,Traits> 的虚受保护成员函数) |
pbasepptrepptr |
返回指向放置区的起始、当前字符和末尾的指针 (受保护成员函数) |
pbump |
令输出序列中的下一位置指针前进 (受保护成员函数) |
setp |
重定位输出序列的起始、下一位置和终止指针 (受保护成员函数) |
回放 |
|
pbackfail [虚] |
将字符放回输入序列,可能修改输入序列 ( std::basic_streambuf<CharT,Traits> 的虚受保护成员函数) |