std::basic_stringstream<CharT,Traits,Allocator>::view
来自cppreference.com
<tbody>
</tbody>
std::basic_string_view<CharT, Traits> view() const noexcept; |
(C++20 起) | |
获得底层字符串对象上的 std::basic_string_view。等价于 return rdbuf()->view();。
参数
(无)
返回值
底层字符串对象上的 std::basic_string_view。
示例
运行此代码
#include <iostream>
#include <sstream>
int main()
{
// 输入/输出流
std::stringstream buf1;
buf1 << 69;
int n = 0;
buf1 >> n;
std::cout << "1) buf1 = [" << buf1.view() << "], n = " << n << '\n';
// 追加模式的输出流
std::ostringstream buf2("test", std::ios_base::ate);
buf2 << '1';
std::cout << "2) buf2 = [" << buf2.view() << "]\n";
// 输入流
std::istringstream inbuf("-42");
inbuf >> n;
std::cout << "3) inbuf = [" << inbuf.view() << "], n = " << n << '\n';
}
输出:
1) buf1 = [69], n = 69
2) buf2 = [test1]
3) inbuf = [-42], n = -42
参阅
(C++20) |
获得底层字符序列上的视图 ( std::basic_stringbuf<CharT,Traits,Allocator> 的公开成员函数)
|