std::basic_stringbuf::str
来自cppreference.com
< cpp | io | basic stringbuf
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
std::basic_string<CharT, Traits, Allocator> str() const; |
(1) | |
void str( const std::basic_string<CharT, Traits, Allocator>& s); |
(2) | |
获取和设置相关的字符串.
1)
创建并返回一个std::basic_string
std::basic_stringbuf
的基本字符序列的拷贝对象,其中包含。对于输入流,返回的字符串包含的字符的范围[eback(), egptr())。输入/输出或输出流,从pbase()包含的字符序列中的最后一个字符,无论egptr(),epptr().原文:
Creates and returns a std::basic_string object containing a copy of this
std::basic_stringbuf
's underlying character sequence. For input-only streams, the returned string contains the characters from the range [eback(), egptr()). For input/output or output-only streams, contains the characters from pbase() to the last character in the sequence regardless of egptr() and epptr().2)
本
std::basic_stringbuf
删除整个基础字符序列,然后配置一个新的底层字符序列s
的内容的副本。指针std::basic_streambuf中初始化如下:原文:
Deletes the entire underlying character sequence of this
std::basic_stringbuf
and then configures a new underlying character sequence containing a copy of the contents of s
. The pointers of std::basic_streambuf are initialized as follows:- 输入流(mode & ios_base::in == true),eback()点的第一个字符,gptr() == eback(),并egptr() == eback() + s.size():随后的输入将读取的第一个字符复制到
s
.原文:For input streams (mode & ios_base::in == true), eback() points at the first character, gptr() == eback(), and egptr() == eback() + s.size(): the subsequent input will read the first character copied froms
. - 对于输出流(mode & ios_base::out == true),pbase()点的第一个字符和epptr() >= pbase() + s.size()(epptr点更远,以下
sputc()
不会立即拨打overflow()
)原文:For output streams (mode & ios_base::out == true), pbase() points at the first character and epptr() >= pbase() + s.size() (epptr is allowed to point farther so that the followingsputc()
wouldn't immediately calloverflow()
)- 对于追加数据流(mode & ios_base::ate == true),pptr() == pbase() + s.size(),以便将后续输出将被追加到最后一个字符复制
s
(C++11 起)原文:For append streams (mode & ios_base::ate == true), pptr() == pbase() + s.size(), so that subsequent output will be appended to the last character copied froms
(C++11 起) - 对于无附加输出流,pptr() == pbase(),以便将后续输出将覆盖从
s
的字符复制.原文:For no-appending output streams, pptr() == pbase(), so that subsequent output will overwrite the characters copied froms
.
-
目录 |
[编辑] 参数
s | - | 一个字符串对象替换的字符序列
原文: a string object holding the replacement character sequence |
[编辑] 返回值
1)
此缓冲区的底层字符序列的字符串对象的一个副本.
原文:
A string object holding a copy of this buffer's underlying character sequence.
2)
(无)
[编辑] 注释
该功能通常可以通过std::basic_stringstream::str().
原文:
This function is typically accessed through std::basic_stringstream::str().
[编辑] 示例
#include <sstream> #include <iostream> int main() { int n; std::istringstream in; // could also use in("1 2") in.rdbuf()->str("1 2"); // set the get area in >> n; std::cout << "after reading the first int from \"1 2\", the int is " << n << ", str() = \"" << in.rdbuf()->str() << "\"\n"; // or in.str() std::ostringstream out("1 2"); out << 3; std::cout << "after writing the int '3' to output stream \"1 2\"" << ", str() = \"" << out.str() << "\"\n"; std::ostringstream ate("1 2", std::ios_base::ate); // C++11 ate << 3; std::cout << "after writing the int '3' to append stream \"1 2\"" << ", str() = \"" << ate.str() << "\"\n"; }
输出:
after reading the first int from "1 2", the int is 1, str() = "1 2" after writing the int '3' to output stream "1 2", str() = "3 2" after writing the int '3' to append stream "1 2", str() = "1 23"
[编辑] 另请参阅
获取或设置字符串设备对象相关的内容 原文: gets or sets the contents of underlying string device object (公共成员函数of std::basic_stringstream )
|