最終更新日時(UTC):
が更新

履歴 編集

function
<sstream>

std::basic_stringbuf::view(C++20)

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

処理系

参照