标准库标头 <strstream> (C++98 中弃用)(C++26 中移除)

来自cppreference.com
< cpp‎ | header


 
 
标准库标头
语言支持
概念
<concepts> (C++20)
诊断
<system_error> (C++11)

内存管理
<memory_resource> (C++17)  
元编程
<type_traits> (C++11)
<ratio> (C++11)
通用工具
<utility>
<tuple> (C++11)
<optional> (C++17)
<variant> (C++17)
<any> (C++17)
<debugging> (C++26)
<expected> (C++23)
<bitset>
<charconv> (C++17)
<format> (C++20)
<bit> (C++20)

字符串
<cuchar> (C++11)

容器
<flat_set> (C++23)
<span> (C++20)
<mdspan> (C++23)
<inplace_vector> (C++26)
迭代器
<iterator>
范围
<ranges> (C++20)
<generator> (C++23)
算法
数值
<cfenv> (C++11)
<complex>
<cmath>
<linalg> (C++26)
<numbers> (C++20)

日期时间
<chrono> (C++11)
本地化
<codecvt> (C++11/17/26*)
<text_encoding> (C++26)
输入/输出
<filesystem> (C++17)
<cstdio>
<cinttypes> (C++11)
<strstream> (C++98/26*)
正则表达式
<regex> (C++11)
并发支持
<stop_token> (C++20)
<thread> (C++11)
<atomic> (C++11)
<rcu> (C++26)
<stdatomic.h> (C++23)
<mutex> (C++11)
<shared_mutex> (C++14)

<condition_variable> (C++11)  
<semaphore> (C++20)
<latch> (C++20)

<barrier> (C++20)
<future> (C++11)
<hazard_pointer> (C++26)

C 兼容
<cstdbool> (C++11/17/20*)  
<ccomplex> (C++11/17/20*)
<ctgmath> (C++11/17/20*)

<cstdalign> (C++11/17/20*)

<ciso646> (C++20 前)

 

此头文件是输入/输出库的一部分。

(C++98 中弃用)(C++26 中移除)
实现原生字符数组设备
(类)
(C++98 中弃用)(C++26 中移除)
实现字符数组输入操作
(类)
(C++98 中弃用)(C++26 中移除)
实现字符数组输出操作
(类)
(C++98 中弃用)(C++26 中移除)
实现字符数组输入/输出操作
(类)

注解

<strstream> 于 C++98 中弃用并于 C++26 中移除(见 P2867R1)。

移除它的理由是 C++20 和 C++23 已提供了更好的替代设施,比如从 std::stringstream 中高效移出字符串的能力(C++20 起提供,见 P0408R7),以及 <spanstream> 库(C++23 起提供,见 P0448R4)。

概要

namespace std {
  class strstreambuf;
  class istrstream;
  class ostrstream;
  class strstream;
}

std::strstreambuf

namespace std {
  class strstreambuf : public basic_streambuf<char> {
  public:
    strstreambuf() : strstreambuf(0) {}
    explicit strstreambuf(streamsize alsize_arg);
    strstreambuf(void* (*palloc_arg)(size_t), void (*pfree_arg)(void*));
    strstreambuf(char* gnext_arg, streamsize n, char* pbeg_arg = nullptr);
    strstreambuf(const char* gnext_arg, streamsize n);
 
    strstreambuf(signed char* gnext_arg, streamsize n,
                 signed char* pbeg_arg = nullptr);
    strstreambuf(const signed char* gnext_arg, streamsize n);
    strstreambuf(unsigned char* gnext_arg, streamsize n,
                 unsigned char* pbeg_arg = nullptr);
    strstreambuf(const unsigned char* gnext_arg, streamsize n);
 
    virtual ~strstreambuf();
 
    void  freeze(bool freezefl = true);
    char* str();
    int   pcount();
 
  protected:
    int_type overflow (int_type c = EOF) override;
    int_type pbackfail(int_type c = EOF) override;
    int_type underflow() override;
    pos_type seekoff(off_type off, ios_base::seekdir way,
                     ios_base::openmode which = ios_base::in | ios_base::out) override;
    pos_type seekpos(pos_type sp,
                     ios_base::openmode which = ios_base::in | ios_base::out) override;
    streambuf* setbuf(char* s, streamsize n) override;
 
  private:
    using strstate = /*位掩码类型*/;      // 仅用于阐释
    static const strstate allocated;    // 仅用于阐释
    static const strstate constant;     // 仅用于阐释
    static const strstate dynamic;      // 仅用于阐释
    static const strstate frozen;       // 仅用于阐释
    strstate strmode;                   // 仅用于阐释
    streamsize alsize;                  // 仅用于阐释
    void* (*palloc)(size_t);            // 仅用于阐释
    void (*pfree)(void*);               // 仅用于阐释
  };
}

std::istrstream

namespace std {
  class istrstream : public basic_istream<char> {
  public:
    explicit istrstream(const char* s);
    explicit istrstream(char* s);
    istrstream(const char* s, streamsize n);
    istrstream(char* s, streamsize n);
    virtual ~istrstream();
 
    strstreambuf* rdbuf() const;
    char* str();
  private:
    strstreambuf sb;            // 仅用于阐释
  };
}

std::ostrstream

namespace std {
  class ostrstream : public basic_ostream<char> {
  public:
    ostrstream();
    ostrstream(char* s, int n, ios_base::openmode mode = ios_base::out);
    virtual ~ostrstream();
 
    strstreambuf* rdbuf() const;
    void freeze(bool freezefl = true);
    char* str();
    int pcount() const;
  private:
    strstreambuf sb;            // 仅用于阐释
  };
}

std::strstream

namespace std {
  class strstream
    : public basic_iostream<char> {
  public:
    // 类型
    using char_type = char;
    using int_type  = char_traits<char>::int_type;
    using pos_type  = char_traits<char>::pos_type;
    using off_type  = char_traits<char>::off_type;
 
    // 构造函数/析构函数
    strstream();
    strstream(char* s, int n,
              ios_base::openmode mode = ios_base::in | ios_base::out);
    virtual ~strstream();
 
    // 成员
    strstreambuf* rdbuf() const;
    void freeze(bool freezefl = true);
    int pcount() const;
    char* str();
 
  private:
    strstreambuf sb;            // 仅用于阐释
  };
}