Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/header/strstream"

From cppreference.com
< cpp‎ | header
m (link to zh)
m (Notes: +{{stddoc|P2867R1}})
 
(8 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{cpp/header/title|strstream}}
+
{{cpp/header/title|strstream|notes={{mark life|deprecated=c++98|removed=c++26}}}}
 
{{cpp/header/navbar}}
 
{{cpp/header/navbar}}
 +
 
This header is part of the [[cpp/io|Input/Output]] library.
 
This header is part of the [[cpp/io|Input/Output]] library.
 +
 
{{dsc begin}}
 
{{dsc begin}}
 
{{dsc h1|Classes}}
 
{{dsc h1|Classes}}
{{dsc class | cpp/io/strstreambuf | notes={{mark deprecated}} | implements raw character array device}}
+
{{dsc inc|cpp/io/dsc strstreambuf}}
{{dsc class | cpp/io/istrstream | notes={{mark deprecated}} | implements character array input operations}}
+
{{dsc inc|cpp/io/dsc istrstream}}
{{dsc class | cpp/io/ostrstream | notes={{mark deprecated}} | implements character array output operations}}
+
{{dsc inc|cpp/io/dsc ostrstream}}
{{dsc class | cpp/io/strstream | notes={{mark deprecated}} | implements character array input/output operations}}
+
{{dsc inc|cpp/io/dsc strstream}}
 
{{dsc end}}
 
{{dsc end}}
  
===Synopsis===
+
===Notes===
 +
{{header|strstream}} is deprecated in C++98 and removed in C++26 (see {{stddoc|P2867R1}}).
  
{{source|1=
+
The reason for removal is that C++20 and C++23 provide superior replacement facilities, such as the ability to move strings efficiently out of {{lc|std::basic_stringstream|std::stringstream}}s (since C++20, see {{stddoc|P0408R7}}), and the {{header|spanstream}} library (since C++23, see {{stddoc|P0448R4}}).
 +
 
 +
===Synopsis===
 +
{{source|
 
namespace std {
 
namespace std {
    class strstreambuf;
+
  class strstreambuf;
    class istrstream;
+
  class istrstream;
    class ostrstream;
+
  class ostrstream;
    class strstream;
+
  class strstream;
 
}
 
}
 
}}
 
}}
Line 23: Line 29:
 
====Class {{lc|std::strstreambuf}}====
 
====Class {{lc|std::strstreambuf}}====
 
{{source|1=
 
{{source|1=
class strstreambuf : public basic_streambuf<char> {
+
namespace std {
public:
+
  class strstreambuf : public basic_streambuf<char> {
     explicit strstreambuf(streamsize alsize_arg = 0);
+
  public:
 +
    strstreambuf() : strstreambuf(0) {}
 +
     explicit strstreambuf(streamsize alsize_arg);
 
     strstreambuf(void* (*palloc_arg)(size_t), void (*pfree_arg)(void*));
 
     strstreambuf(void* (*palloc_arg)(size_t), void (*pfree_arg)(void*));
     strstreambuf(char* gnext_arg, streamsize n, char* pbeg_arg = 0);
+
     strstreambuf(char* gnext_arg, streamsize n, char* pbeg_arg = nullptr);
 
     strstreambuf(const char* gnext_arg, streamsize n);
 
     strstreambuf(const char* gnext_arg, streamsize n);
     strstreambuf(signed char* gnext_arg, streamsize n, signed char* pbeg_arg = 0);
+
 
 +
     strstreambuf(signed char* gnext_arg, streamsize n,
 +
                signed char* pbeg_arg = nullptr);
 
     strstreambuf(const signed char* gnext_arg, streamsize n);
 
     strstreambuf(const signed char* gnext_arg, streamsize n);
     strstreambuf(unsigned char* gnext_arg, streamsize n, unsigned char* pbeg_arg = 0);
+
     strstreambuf(unsigned char* gnext_arg, streamsize n,
 +
                unsigned char* pbeg_arg = nullptr);
 
     strstreambuf(const unsigned char* gnext_arg, streamsize n);
 
     strstreambuf(const unsigned char* gnext_arg, streamsize n);
 +
 
     virtual ~strstreambuf();
 
     virtual ~strstreambuf();
  
     void freeze(bool freezefl = true);
+
     void freeze(bool freezefl = true);
 
     char* str();
 
     char* str();
     int pcount();
+
     int   pcount();
  
protected:
+
  protected:
     virtual int_type overflow (int_type c = EOF);
+
     int_type overflow (int_type c = EOF) override;
     virtual int_type pbackfail(int_type c = EOF);
+
     int_type pbackfail(int_type c = EOF) override;
     virtual int_type underflow();
+
     int_type underflow() override;
     virtual pos_type seekoff(off_type off, ios_base::seekdir way,
+
     pos_type seekoff(off_type off, ios_base::seekdir way,
                            ios_base::openmode which = ios_base::in{{!}}ios_base::out);
+
                    ios_base::openmode which = ios_base::in {{!}} ios_base::out) override;
     virtual pos_type seekpos(pos_type sp,
+
     pos_type seekpos(pos_type sp,
                            ios_base::openmode which = ios_base::in{{!}}ios_base::out);
+
                    ios_base::openmode which = ios_base::in {{!}} ios_base::out) override;
     virtual streambuf* setbuf(char* s, streamsize n);
+
     streambuf* setbuf(char* s, streamsize n) override;
  
private:
+
  private:
     typedef /*bitmask type*/ strstate; // exposition only
+
     using strstate = /*bitmask type*/; // exposition only
     static const strstate allocated; // exposition only
+
     static const strstate allocated;   // exposition only
     static const strstate constant; // exposition only
+
     static const strstate constant;     // exposition only
     static const strstate dynamic; // exposition only
+
     static const strstate dynamic;     // exposition only
     static const strstate frozen; // exposition only
+
     static const strstate frozen;       // exposition only
     strstate strmode; // exposition only
+
     strstate strmode;                   // exposition only
     streamsize alsize; // exposition only
+
     streamsize alsize;                 // exposition only
     void* (*palloc)(size_t); // exposition only
+
     void* (*palloc)(size_t);           // exposition only
     void (*pfree)(void*); // exposition only
+
     void (*pfree)(void*);               // exposition only
};
+
  };
 +
}
 
}}
 
}}
  
 
====Class {{lc|std::istrstream}}====
 
====Class {{lc|std::istrstream}}====
 
{{source|1=
 
{{source|1=
class istrstream : public basic_istream<char> {
+
namespace std {
public:
+
  class istrstream : public basic_istream<char> {
 +
  public:
 
     explicit istrstream(const char* s);
 
     explicit istrstream(const char* s);
 
     explicit istrstream(char* s);
 
     explicit istrstream(char* s);
Line 73: Line 87:
  
 
     strstreambuf* rdbuf() const;
 
     strstreambuf* rdbuf() const;
     char *str();
+
     char* str();
 
+
  private:
private:
+
     strstreambuf sb;           // exposition only
     strstreambuf sb; // exposition only
+
  };
};
+
}
 
}}
 
}}
  
 
====Class {{lc|std::ostrstream}}====
 
====Class {{lc|std::ostrstream}}====
 
{{source|1=
 
{{source|1=
class ostrstream : public basic_ostream<char> {
+
namespace std {
public:
+
  class ostrstream : public basic_ostream<char> {
 +
  public:
 
     ostrstream();
 
     ostrstream();
 
     ostrstream(char* s, int n, ios_base::openmode mode = ios_base::out);
 
     ostrstream(char* s, int n, ios_base::openmode mode = ios_base::out);
Line 92: Line 107:
 
     char* str();
 
     char* str();
 
     int pcount() const;
 
     int pcount() const;
 
+
  private:
private:
+
     strstreambuf sb;           // exposition only
     strstreambuf sb; // exposition only
+
  };
};
+
}
 
}}
 
}}
  
 
====Class {{lc|std::strstream}}====
 
====Class {{lc|std::strstream}}====
 
{{source|1=
 
{{source|1=
class strstream : public basic_iostream<char> {
+
namespace std {
public:
+
  class strstream
     // Types
+
    : public basic_iostream<char> {
     typedef char char_type;
+
  public:
     typedef typename char_traits<char>::int_type int_type;
+
     // types
     typedef typename char_traits<char>::pos_type pos_type;
+
     using char_type = char;
     typedef typename char_traits<char>::off_type off_type;
+
     using int_type  = char_traits<char>::int_type;
 +
     using pos_type  = char_traits<char>::pos_type;
 +
     using off_type  = char_traits<char>::off_type;
  
 
     // constructors/destructor
 
     // constructors/destructor
 
     strstream();
 
     strstream();
 
     strstream(char* s, int n,
 
     strstream(char* s, int n,
    ios_base::openmode mode = ios_base::in|ios_base::out);
+
              ios_base::openmode mode = ios_base::in {{!}} ios_base::out);
 
     virtual ~strstream();
 
     virtual ~strstream();
  
     // Members:
+
     // members
 
     strstreambuf* rdbuf() const;
 
     strstreambuf* rdbuf() const;
 
     void freeze(bool freezefl = true);
 
     void freeze(bool freezefl = true);
Line 120: Line 137:
 
     char* str();
 
     char* str();
  
private:
+
  private:
     strstreambuf sb; // exposition only
+
     strstreambuf sb;           // exposition only
};
+
  };
 +
}
 
}}
 
}}
  
{{langlinks|zh}}
+
{{langlinks|es|ja|zh}}

Latest revision as of 20:56, 5 April 2024

 
 
Standard library headers
 

This header is part of the Input/Output library.

Contents

Classes

(deprecated in C++98)(removed in C++26)
implements raw character array device
(class) [edit]
(deprecated in C++98)(removed in C++26)
implements character array input operations
(class) [edit]
(deprecated in C++98)(removed in C++26)
implements character array output operations
(class) [edit]
(deprecated in C++98)(removed in C++26)
implements character array input/output operations
(class) [edit]

[edit] Notes

<strstream> is deprecated in C++98 and removed in C++26 (see P2867R1).

The reason for removal is that C++20 and C++23 provide superior replacement facilities, such as the ability to move strings efficiently out of std::stringstreams (since C++20, see P0408R7), and the <spanstream> library (since C++23, see P0448R4).

[edit] Synopsis

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

[edit] Class 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 = /*bitmask type*/;  // exposition only
    static const strstate allocated;    // exposition only
    static const strstate constant;     // exposition only
    static const strstate dynamic;      // exposition only
    static const strstate frozen;       // exposition only
    strstate strmode;                   // exposition only
    streamsize alsize;                  // exposition only
    void* (*palloc)(size_t);            // exposition only
    void (*pfree)(void*);               // exposition only
  };
}

[edit] Class 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;            // exposition only
  };
}

[edit] Class 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;            // exposition only
  };
}

[edit] Class std::strstream

namespace std {
  class strstream
    : public basic_iostream<char> {
  public:
    // types
    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;
 
    // constructors/destructor
    strstream();
    strstream(char* s, int n,
              ios_base::openmode mode = ios_base::in | ios_base::out);
    virtual ~strstream();
 
    // members
    strstreambuf* rdbuf() const;
    void freeze(bool freezefl = true);
    int pcount() const;
    char* str();
 
  private:
    strstreambuf sb;            // exposition only
  };
}