标准库头文件 <sstream>

来自cppreference.com
< cpp‎ | header
 
 
 

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

实现原生字符串设备
(类模板)
实现高层字符串流输入操作
(类模板)
实现高层字符串流输出操作
(类模板)
实现高层字符串流输入/输出操作
(类模板)

typedef

stringbuf basic_stringbuf<char>
wstringbuf basic_stringbuf<wchar_t>
istringstream basic_istringstream<char>
wistringstream basic_istringstream<wchar_t>
ostringstream basic_ostringstream<char>
wostringstream basic_ostringstream<wchar_t>
stringstream basic_stringstream<char>
wstringstream basic_stringstream<wchar_t>

函数

特化 std::swap 算法
(函数模板)
特化 std::swap 算法
(函数模板)
特化 std::swap 算法
(函数模板)
特化 std::swap 算法
(函数模板)

概要

namespace std {
 
    template <class charT,
              class traits = char_traits<charT>,
              class Allocator = allocator<charT> >
        class basic_stringbuf;
    typedef basic_stringbuf<char> stringbuf;
    typedef basic_stringbuf<wchar_t> wstringbuf;
    template <class charT, class traits, class Allocator>
        void swap(basic_stringbuf<charT, traits, Allocator>& x,
                  basic_stringbuf<charT, traits, Allocator>& y);
 
    template <class charT,
              class traits = char_traits<charT>,
              class Allocator = allocator<charT> >
        class basic_istringstream;
    typedef basic_istringstream<char> istringstream;
    typedef basic_istringstream<wchar_t> wistringstream;
    template <class charT, class traits, class Allocator>
        void swap(basic_istringstream<charT, traits, Allocator>& x,
                  basic_istringstream<charT, traits, Allocator>& y);
 
    template <class charT,
              class traits = char_traits<charT>,
              class Allocator = allocator<charT> >
        class basic_ostringstream;
    typedef basic_ostringstream<char> ostringstream;
    typedef basic_ostringstream<wchar_t> wostringstream;
    template <class charT, class traits, class Allocator>
        void swap(basic_ostringstream<charT, traits, Allocator>& x,
                  basic_ostringstream<charT, traits, Allocator>& y);
 
    template <class charT,
              class traits = char_traits<charT>,
              class Allocator = allocator<charT> >
        class basic_stringstream;
    typedef basic_stringstream<char> stringstream;
    typedef basic_stringstream<wchar_t> wstringstream;
    template <class charT, class traits, class Allocator>
        void swap(basic_stringstream<charT, traits, Allocator>& x,
                  basic_stringstream<charT, traits, Allocator>& y);
}

std::basic_stringbuf

template <class charT,
          class traits = char_traits<charT>,
          class Allocator = allocator<charT> >
class basic_stringbuf : public basic_streambuf<charT,traits> {
 public:
    typedef charT char_type;
    typedef typename traits::int_type int_type;
    typedef typename traits::pos_type pos_type;
    typedef typename traits::off_type off_type;
    typedef traits traits_type;
    typedef Allocator allocator_type;
 
    // 构造函数:
    explicit basic_stringbuf(ios_base::openmode which = ios_base::in|ios_base::out);
    explicit basic_stringbuf(const basic_string<charT,traits,Allocator>& str,
                             ios_base::openmode which = ios_base::in|ios_base::out);
    basic_stringbuf(const basic_stringbuf& rhs) = delete;
    basic_stringbuf(basic_stringbuf&& rhs);
 
    // 赋值与交换:
    basic_stringbuf& operator=(const basic_stringbuf& rhs) = delete;
    basic_stringbuf& operator=(basic_stringbuf&& rhs);
    void swap(basic_stringbuf& rhs);
 
    // 获取与设置:
    basic_string<charT,traits,Allocator> str() const;
    void str(const basic_string<charT,traits,Allocator>& s);
 
 protected:
    // 覆盖的虚函数:
    virtual int_type underflow();
    virtual int_type pbackfail(int_type c = traits::eof());
    virtual int_type overflow (int_type c = traits::eof());
    virtual basic_streambuf<charT,traits>* setbuf(charT*, streamsize);
    virtual pos_type seekoff(off_type off, ios_base::seekdir way,
                             ios_base::openmode which = ios_base::in|ios_base::out);
    virtual pos_type seekpos(pos_type sp,
                             ios_base::openmode which = ios_base::in|ios_base::out);
 
 private:
    ios_base::openmode mode; // 仅用于阐释
};

std::basic_istringstream

template <class charT,
          class traits = char_traits<charT>,
          class Allocator = allocator<charT> >
class basic_istringstream : public basic_istream<charT,traits> {
 public:
    typedef charT char_type;
    typedef typename traits::int_type int_type;
    typedef typename traits::pos_type pos_type;
    typedef typename traits::off_type off_type;
    typedef traits traits_type;
    typedef Allocator allocator_type;
 
    // 构造函数:
    explicit basic_istringstream(ios_base::openmode which = ios_base::in);
    explicit basic_istringstream(const basic_string<charT,traits,Allocator>& str,
                                 ios_base::openmode which = ios_base::in);
    basic_istringstream(const basic_istringstream& rhs) = delete;
    basic_istringstream(basic_istringstream&& rhs);
 
    // 赋值与交换:
    basic_istringstream& operator=(const basic_istringstream& rhs) = delete;
    basic_istringstream& operator=(basic_istringstream&& rhs);
    void swap(basic_istringstream& rhs);
 
    // 成员:
    basic_stringbuf<charT,traits,Allocator>* rdbuf() const;
    basic_string<charT,traits,Allocator> str() const;
    void str(const basic_string<charT,traits,Allocator>& s);
 
 private:
    basic_stringbuf<charT,traits,Allocator> sb; // 仅用于阐释
};

std::basic_ostringstream

template <class charT,
          class traits = char_traits<charT>,
          class Allocator = allocator<charT> >
class basic_ostringstream : public basic_ostream<charT,traits> {
 public:
    // 类型:
    typedef charT char_type;
    typedef typename traits::int_type int_type;
    typedef typename traits::pos_type pos_type;
    typedef typename traits::off_type off_type;
    typedef traits traits_type;
    typedef Allocator allocator_type;
 
    // 构造函数/析构函数:
    explicit basic_ostringstream(ios_base::openmode which = ios_base::out);
    explicit basic_ostringstream(const basic_string<charT,traits,Allocator>& str,
                                 ios_base::openmode which = ios_base::out);
     basic_ostringstream(const basic_ostringstream& rhs) = delete;
     basic_ostringstream(basic_ostringstream&& rhs);
 
    // 赋值/交换:
    basic_ostringstream& operator=(const basic_ostringstream& rhs) = delete;
    basic_ostringstream& operator=(basic_ostringstream&& rhs);
    void swap(basic_ostringstream& rhs);
 
    // 成员:
    basic_stringbuf<charT,traits,Allocator>* rdbuf() const;
    basic_string<charT,traits,Allocator> str() const;
    void str(const basic_string<charT,traits,Allocator>& s);
 
 private:
    basic_stringbuf<charT,traits,Allocator> sb; // 仅用于阐释
};

std::basic_stringstream

template <class charT,
          class traits = char_traits<charT>,
          class Allocator = allocator<charT> >
class basic_stringstream : public basic_iostream<charT,traits> {
 public:
    // 类型:
    typedef charT char_type;
    typedef typename traits::int_type int_type;
    typedef typename traits::pos_type pos_type;
    typedef typename traits::off_type off_type;
    typedef traits traits_type;
    typedef Allocator allocator_type;
 
    // 构造函数/析构函数
    explicit basic_stringstream(ios_base::openmode which = ios_base::out|ios_base::in);
    explicit basic_stringstream(const basic_string<charT,traits,Allocator>& str,
                                ios_base::openmode which = ios_base::out|ios_base::in);
    basic_stringstream(const basic_stringstream& rhs) = delete;
    basic_stringstream(basic_stringstream&& rhs);
 
    // 赋值/交换:
    basic_stringstream& operator=(const basic_stringstream& rhs) = delete;
    basic_stringstream& operator=(basic_stringstream&& rhs);
    void swap(basic_stringstream& rhs);
 
    // 成员:
    basic_stringbuf<charT,traits,Allocator>* rdbuf() const;
    basic_string<charT,traits,Allocator> str() const;
    void str(const basic_string<charT,traits,Allocator>& str);
 
 private:
    basic_stringbuf<charT, traits> sb; // 仅用于阐释
};