std::basic_istringstream::str
来自cppreference.com
< cpp | io | basic istringstream
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
std::basic_string<CharT,Traits,Allocator> str() const; |
(1) | |
void str(const std::basic_string<CharT,Traits,Allocator>& new_str); |
(2) | |
管理的基本字符串对象的内容.....
1) 原文:
Manages the contents of the underlying string object.
返回的副本的基础字符串,如果通过调用rdbuf()->str().
2) 原文:
Returns a copy of the underlying string as if by calling rdbuf()->str().
通过调用rdbuf()->str(new_str)的内容替换底层的字符串,就好象.
原文:
Replaces the contents of the underlying string as if by calling rdbuf()->str(new_str).
目录 |
[编辑] 参数
new_str | - | 底层的字符串的新的内容
原文: new contents of the underlying string |
[编辑] 返回值
1)的基础字符串对象的一个副本.
2) 原文:
a copy of the underlying string object.
(无)
[编辑] 为例
#include <sstream> #include <iostream> int main() { int n; std::istringstream in; // could also use in("1 2") in.str("1 2"); in >> n; std::cout << "after reading the first int from \"1 2\", the int is " << n << ", str() = \"" << in.str() << "\"\n"; 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); 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"
[编辑] 另请参阅
替换或获得相关联的字符串的一个副本 原文: replaces or obtains a copy of the associated character string (公共成员函数of std::basic_stringbuf )
|