命名空间
变体
操作

std::basic_stringstream<CharT,Traits,Allocator>::view

来自 cppreference.com
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()
{
    // input/output stream
    std::stringstream buf1;
    buf1 << 69;
    int n = 0;
    buf1 >> n;
    std::cout << "1) buf1 = [" << buf1.view() << "], n = " << n << '\n';
 
    // output stream in append mode
    std::ostringstream buf2("test", std::ios_base::ate);
    buf2 << '1';
    std::cout << "2) buf2 = [" << buf2.view() << "]\n";
 
    // input stream
    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> 的公有成员函数) [编辑]