- spanstream[meta header]
- std[meta namespace]
- class template[meta id-type]
- cpp23[meta cpp]
- spanstream,wspanstream[meta alias]
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>;
}
- char_traits[link /reference/string/char_traits.md]
- basic_iostream[link /reference/istream/basic_iostream.md]
std::basic_spanstreamクラスは、std::span を使用した固定長ストリームバッファを出力先・入力元とするストリームであり、読み取りと書き込みの両方の操作ができる。
| 名前 |
説明 |
対応バージョン |
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;
}
- std::spanstream[color ff0000]
- std::span[link /reference/span/span.md]
- span()[link /reference/spanstream/basic_spanstream/span.md]
- data()[link /reference/span/span/data.md]
Hello 123 World 45.67
word1="Hello", num1=123, word2="World", num2=45.67