📄 std_sstream.h
字号:
* @c ios_base::in is automatically included in @a mode. * * Initializes @c sb using @c mode|in, and passes @c &sb to the base * class initializer. Does not allocate any buffer. * * @if maint * That's a lie. We initialize the base class with NULL, because the * string class does its own memory management. * @endif */ explicit basic_istringstream(ios_base::openmode __mode = ios_base::in) : __istream_type(NULL), _M_stringbuf(__mode | ios_base::in) { this->init(&_M_stringbuf); } /** * @brief Starts with an existing string buffer. * @param str A string to copy as a starting buffer. * @param mode Whether the buffer can read, or write, or both. * * @c ios_base::in is automatically included in @a mode. * * Initializes @c sb using @a str and @c mode|in, and passes @c &sb * to the base class initializer. * * @if maint * That's a lie. We initialize the base class with NULL, because the * string class does its own memory management. * @endif */ explicit basic_istringstream(const __string_type& __str, ios_base::openmode __mode = ios_base::in) : __istream_type(NULL), _M_stringbuf(__str, __mode | ios_base::in) { this->init(&_M_stringbuf); } /** * @brief The destructor does nothing. * * The buffer is deallocated by the stringbuf object, not the * formatting stream. */ ~basic_istringstream() { } // Members: /** * @brief Accessing the underlying buffer. * @return The current basic_stringbuf buffer. * * This hides both signatures of std::basic_ios::rdbuf(). */ __stringbuf_type* rdbuf() const { return const_cast<__stringbuf_type*>(&_M_stringbuf); } /** * @brief Copying out the string buffer. * @return @c rdbuf()->str() */ __string_type str() const { return _M_stringbuf.str(); } /** * @brief Setting a new buffer. * @param s The string to use as a new sequence. * * Calls @c rdbuf()->str(s). */ void str(const __string_type& __s) { _M_stringbuf.str(__s); } }; // [27.7.3] Template class basic_ostringstream /** * @brief Controlling output for std::string. * * This class supports writing to objects of type std::basic_string, * using the inherited functions from std::basic_ostream. To control * the associated sequence, an instance of std::basic_stringbuf is used, * which this page refers to as @c sb. */ template <typename _CharT, typename _Traits, typename _Alloc> class basic_ostringstream : public basic_ostream<_CharT, _Traits> { public: // Types: typedef _CharT char_type; typedef _Traits traits_type;#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS// 251. basic_stringbuf missing allocator_type typedef _Alloc allocator_type;#endif typedef typename traits_type::int_type int_type; typedef typename traits_type::pos_type pos_type; typedef typename traits_type::off_type off_type; // Non-standard types: typedef basic_string<_CharT, _Traits, _Alloc> __string_type; typedef basic_stringbuf<_CharT, _Traits, _Alloc> __stringbuf_type; typedef basic_ostream<char_type, traits_type> __ostream_type; private: /** * @if maint * @doctodo * @endif */ __stringbuf_type _M_stringbuf; public: // Constructors/destructor: /** * @brief Default constructor starts with an empty string buffer. * @param mode Whether the buffer can read, or write, or both. * * @c ios_base::out is automatically included in @a mode. * * Initializes @c sb using @c mode|out, and passes @c &sb to the base * class initializer. Does not allocate any buffer. * * @if maint * That's a lie. We initialize the base class with NULL, because the * string class does its own memory management. * @endif */ explicit basic_ostringstream(ios_base::openmode __mode = ios_base::out) : __ostream_type(NULL), _M_stringbuf(__mode | ios_base::out) { this->init(&_M_stringbuf); } /** * @brief Starts with an existing string buffer. * @param str A string to copy as a starting buffer. * @param mode Whether the buffer can read, or write, or both. * * @c ios_base::out is automatically included in @a mode. * * Initializes @c sb using @a str and @c mode|out, and passes @c &sb * to the base class initializer. * * @if maint * That's a lie. We initialize the base class with NULL, because the * string class does its own memory management. * @endif */ explicit basic_ostringstream(const __string_type& __str, ios_base::openmode __mode = ios_base::out) : __ostream_type(NULL), _M_stringbuf(__str, __mode | ios_base::out) { this->init(&_M_stringbuf); } /** * @brief The destructor does nothing. * * The buffer is deallocated by the stringbuf object, not the * formatting stream. */ ~basic_ostringstream() { } // Members: /** * @brief Accessing the underlying buffer. * @return The current basic_stringbuf buffer. * * This hides both signatures of std::basic_ios::rdbuf(). */ __stringbuf_type* rdbuf() const { return const_cast<__stringbuf_type*>(&_M_stringbuf); } /** * @brief Copying out the string buffer. * @return @c rdbuf()->str() */ __string_type str() const { return _M_stringbuf.str(); } /** * @brief Setting a new buffer. * @param s The string to use as a new sequence. * * Calls @c rdbuf()->str(s). */ void str(const __string_type& __s) { _M_stringbuf.str(__s); } }; // [27.7.4] Template class basic_stringstream /** * @brief Controlling input and output for std::string. * * This class supports reading from and writing to objects of type * std::basic_string, using the inherited functions from * std::basic_iostream. To control the associated sequence, an instance * of std::basic_stringbuf is used, which this page refers to as @c sb. */ template <typename _CharT, typename _Traits, typename _Alloc> class basic_stringstream : public basic_iostream<_CharT, _Traits> { public: // Types: typedef _CharT char_type; typedef _Traits traits_type;#ifdef _GLIBCPP_RESOLVE_LIB_DEFECTS// 251. basic_stringbuf missing allocator_type typedef _Alloc allocator_type;#endif typedef typename traits_type::int_type int_type; typedef typename traits_type::pos_type pos_type; typedef typename traits_type::off_type off_type; // Non-standard Types: typedef basic_string<_CharT, _Traits, _Alloc> __string_type; typedef basic_stringbuf<_CharT, _Traits, _Alloc> __stringbuf_type; typedef basic_iostream<char_type, traits_type> __iostream_type; private: /** * @if maint * @doctodo * @endif */ __stringbuf_type _M_stringbuf; public: // Constructors/destructors /** * @brief Default constructor starts with an empty string buffer. * @param mode Whether the buffer can read, or write, or both. * * Initializes @c sb using @c mode, and passes @c &sb to the base * class initializer. Does not allocate any buffer. * * @if maint * That's a lie. We initialize the base class with NULL, because the * string class does its own memory management. * @endif */ explicit basic_stringstream(ios_base::openmode __m = ios_base::out | ios_base::in) : __iostream_type(NULL), _M_stringbuf(__m) { this->init(&_M_stringbuf); } /** * @brief Starts with an existing string buffer. * @param str A string to copy as a starting buffer. * @param mode Whether the buffer can read, or write, or both. * * Initializes @c sb using @a str and @c mode, and passes @c &sb * to the base class initializer. * * @if maint * That's a lie. We initialize the base class with NULL, because the * string class does its own memory management. * @endif */ explicit basic_stringstream(const __string_type& __str, ios_base::openmode __m = ios_base::out | ios_base::in) : __iostream_type(NULL), _M_stringbuf(__str, __m) { this->init(&_M_stringbuf); } /** * @brief The destructor does nothing. * * The buffer is deallocated by the stringbuf object, not the * formatting stream. */ ~basic_stringstream() { } // Members: /** * @brief Accessing the underlying buffer. * @return The current basic_stringbuf buffer. * * This hides both signatures of std::basic_ios::rdbuf(). */ __stringbuf_type* rdbuf() const { return const_cast<__stringbuf_type*>(&_M_stringbuf); } /** * @brief Copying out the string buffer. * @return @c rdbuf()->str() */ __string_type str() const { return _M_stringbuf.str(); } /** * @brief Setting a new buffer. * @param s The string to use as a new sequence. * * Calls @c rdbuf()->str(s). */ void str(const __string_type& __s) { _M_stringbuf.str(__s); } };} // namespace std#ifdef _GLIBCPP_NO_TEMPLATE_EXPORT# define export#endif#ifdef _GLIBCPP_FULLY_COMPLIANT_HEADERS# include <bits/sstream.tcc>#endif#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -