basic_string_view<CharT, Traits> view() const noexcept;
概要
文字列ビューオブジェクトの取得を行う。
戻り値
バッファが初期化されている場合、gptr()
とegptr()
の間の文字列を指すbasic_string_view
オブジェクトを返す。
それ以外の場合、pbase()
とepptr()
の間の文字列を指すbasic_string_view
オブジェクトを返す。
例
#include <iostream>
#include <sstream>
#include <string_view>
int main()
{
std::stringbuf buf("Hello World");
std::string_view sv = buf.view();
std::cout << sv.substr(0, 5) << std::endl; // "Hello"
}
出力
Hello
バージョン
言語
- C++20
処理系
- Clang: 12 ✅
- GCC: 12 ✅
- Visual C++: 2019 Update 10 ✅