GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • cpprefjp - C++日本語リファレンス
  • GitHub Project

This view

  • Original page
  • New address

GeezerVison is showing cpprefjp.github.io — std::basic_spanstream - cpprefjp C++日本語リファレンス

  1. リファレンス
  2. spanstream
  3. basic_spanstream

最終更新日時: 2026年01月08日 20時45分05秒 (JST)
yoh が更新

履歴 編集

class template
<spanstream>

std::basic_spanstream(C++23)

namespace std {
  template <class CharT,
            class Traits = char_traits<CharT> >
  class basic_spanstream : public basic_iostream<CharT, Traits>;

  using spanstream  = basic_spanstream<char>;
  using wspanstream = basic_spanstream<wchar_t>;
}

概要

std::basic_spanstreamクラスは、std::span を使用した固定長ストリームバッファを出力先・入力元とするストリームであり、読み取りと書き込みの両方の操作ができる。

メンバ関数

名前 説明 対応バージョン
(constructor) コンストラクタ C++23
operator= ムーブ代入 C++23
swap 値の交換 C++23
rdbuf ストリームバッファオブジェクトの設定・取得 C++23
span std::spanオブジェクトの設定・取得 C++23

非メンバ関数

名前 説明 対応バージョン
swap 2つのオブジェクトを入れ替える C++23

メンバ型

名前 説明 対応バージョン
char_type テンプレート仮引数CharT C++23
int_type Traits::int_type C++23
pos_type Traits::pos_type C++23
off_type Traits::off_type C++23
traits_type テンプレート仮引数Traits C++23

例

#include <iostream>
#include <span>
#include <spanstream>
#include <string>

int main()
{
  // 読み取りと書き込みが可能なストリーム
  char buf[256] = {};
  std::span<char> span{buf};
  std::spanstream ss(span);

  // データを書き込む
  ss << "Hello " << 123 << " World " << 45.67;

  // 先頭から文字列出力
  const char* p = ss.span().data();
  std::cout << p << std::endl;

  // 読み取り位置をリセット
  ss.seekg(0);

  std::string word1, word2;
  int num1;
  double num2;

  // データを読み取る
  ss >> word1 >> num1 >> word2 >> num2;

  // データを出力
  std::cout << std::endl
            << "word1=\"" << word1 
            << "\", num1=" << num1 
            << ", word2=\"" << word2 
            << "\", num2=" << num2 << std::endl;
}

出力

Hello 123 World 45.67

word1="Hello", num1=123, word2="World", num2=45.67

バージョン

言語

  • C++23

処理系

  • Clang: ??
  • GCC: ??
  • Visual C++: ??

参照

  • P0448R4 A strstream replacement using span<charT> as buffer
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.