⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 std_fstream.h

📁 linux下编程用 编译软件
💻 H
📖 第 1 页 / 共 2 页
字号:
   *  @brief  Controlling input for files.   *   *  This class supports reading from named files, using the inherited   *  functions from std::basic_istream.  To control the associated   *  sequence, an instance of std::basic_filebuf is used, which this page   *  refers to as @c sb.  */  template<typename _CharT, typename _Traits>    class basic_ifstream : public basic_istream<_CharT, _Traits>    {    public:      // Types:      typedef _CharT 					char_type;      typedef _Traits 					traits_type;      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_filebuf<char_type, traits_type> 	__filebuf_type;      typedef basic_istream<char_type, traits_type>	__istream_type;    private:      __filebuf_type	_M_filebuf;    public:      // Constructors/Destructors:      /**       *  @brief  Default constructor.       *       *  Initializes @c sb using its default constructor, and passes       *  @c &sb to the base class initializer.  Does not open any files       *  (you haven't given it a filename to open).      */      basic_ifstream() : __istream_type(), _M_filebuf()      { this->init(&_M_filebuf); }      /**       *  @brief  Create an input file stream.       *  @param  s  Null terminated string specifying the filename.       *  @param  mode  Open file in specified mode (see std::ios_base).       *       *  @c ios_base::in is automatically included in @a mode.       *       *  Tip:  When using std::string to hold the filename, you must use       *  .c_str() before passing it to this constructor.      */      explicit      basic_ifstream(const char* __s, ios_base::openmode __mode = ios_base::in)      : __istream_type(), _M_filebuf()      {	this->init(&_M_filebuf);	this->open(__s, __mode);      }      /**       *  @brief  The destructor does nothing.       *       *  The file is closed by the filebuf object, not the formatting       *  stream.      */      ~basic_ifstream()      { }      // Members:      /**       *  @brief  Accessing the underlying buffer.       *  @return  The current basic_filebuf buffer.       *       *  This hides both signatures of std::basic_ios::rdbuf().      */      __filebuf_type*      rdbuf() const      { return const_cast<__filebuf_type*>(&_M_filebuf); }      /**       *  @brief  Wrapper to test for an open file.       *  @return  @c rdbuf()->is_open()      */      bool      is_open()      { return _M_filebuf.is_open(); }      // _GLIBCXX_RESOLVE_LIB_DEFECTS      // 365. Lack of const-qualification in clause 27      bool      is_open() const      { return _M_filebuf.is_open(); }      /**       *  @brief  Opens an external file.       *  @param  s  The name of the file.       *  @param  mode  The open mode flags.       *       *  Calls @c std::basic_filebuf::open(s,mode|in).  If that function       *  fails, @c failbit is set in the stream's error state.       *       *  Tip:  When using std::string to hold the filename, you must use       *  .c_str() before passing it to this constructor.      */      void      open(const char* __s, ios_base::openmode __mode = ios_base::in)      {	if (!_M_filebuf.open(__s, __mode | ios_base::in))	  this->setstate(ios_base::failbit);	else	  // _GLIBCXX_RESOLVE_LIB_DEFECTS	  // 409. Closing an fstream should clear error state	  this->clear();      }      /**       *  @brief  Close the file.       *       *  Calls @c std::basic_filebuf::close().  If that function       *  fails, @c failbit is set in the stream's error state.      */      void      close()      {	if (!_M_filebuf.close())	  this->setstate(ios_base::failbit);      }    };  // [27.8.1.8] Template class basic_ofstream  /**   *  @brief  Controlling output for files.   *   *  This class supports reading from named files, using the inherited   *  functions from std::basic_ostream.  To control the associated   *  sequence, an instance of std::basic_filebuf is used, which this page   *  refers to as @c sb.  */  template<typename _CharT, typename _Traits>    class basic_ofstream : public basic_ostream<_CharT,_Traits>    {    public:      // Types:      typedef _CharT 					char_type;      typedef _Traits 					traits_type;      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_filebuf<char_type, traits_type> 	__filebuf_type;      typedef basic_ostream<char_type, traits_type>	__ostream_type;    private:      __filebuf_type	_M_filebuf;    public:      // Constructors:      /**       *  @brief  Default constructor.       *       *  Initializes @c sb using its default constructor, and passes       *  @c &sb to the base class initializer.  Does not open any files       *  (you haven't given it a filename to open).      */      basic_ofstream(): __ostream_type(), _M_filebuf()      { this->init(&_M_filebuf); }      /**       *  @brief  Create an output file stream.       *  @param  s  Null terminated string specifying the filename.       *  @param  mode  Open file in specified mode (see std::ios_base).       *       *  @c ios_base::out|ios_base::trunc is automatically included in       *  @a mode.       *       *  Tip:  When using std::string to hold the filename, you must use       *  .c_str() before passing it to this constructor.      */      explicit      basic_ofstream(const char* __s,		     ios_base::openmode __mode = ios_base::out|ios_base::trunc)      : __ostream_type(), _M_filebuf()      {	this->init(&_M_filebuf);	this->open(__s, __mode);      }      /**       *  @brief  The destructor does nothing.       *       *  The file is closed by the filebuf object, not the formatting       *  stream.      */      ~basic_ofstream()      { }      // Members:      /**       *  @brief  Accessing the underlying buffer.       *  @return  The current basic_filebuf buffer.       *       *  This hides both signatures of std::basic_ios::rdbuf().      */      __filebuf_type*      rdbuf() const      { return const_cast<__filebuf_type*>(&_M_filebuf); }      /**       *  @brief  Wrapper to test for an open file.       *  @return  @c rdbuf()->is_open()      */      bool      is_open()      { return _M_filebuf.is_open(); }      // _GLIBCXX_RESOLVE_LIB_DEFECTS      // 365. Lack of const-qualification in clause 27      bool      is_open() const      { return _M_filebuf.is_open(); }      /**       *  @brief  Opens an external file.       *  @param  s  The name of the file.       *  @param  mode  The open mode flags.       *       *  Calls @c std::basic_filebuf::open(s,mode|out|trunc).  If that       *  function fails, @c failbit is set in the stream's error state.       *       *  Tip:  When using std::string to hold the filename, you must use       *  .c_str() before passing it to this constructor.      */      void      open(const char* __s,	   ios_base::openmode __mode = ios_base::out | ios_base::trunc)      {	if (!_M_filebuf.open(__s, __mode | ios_base::out))	  this->setstate(ios_base::failbit);	else	  // _GLIBCXX_RESOLVE_LIB_DEFECTS	  // 409. Closing an fstream should clear error state	  this->clear();      }      /**       *  @brief  Close the file.       *       *  Calls @c std::basic_filebuf::close().  If that function       *  fails, @c failbit is set in the stream's error state.      */      void      close()      {	if (!_M_filebuf.close())	  this->setstate(ios_base::failbit);      }    };  // [27.8.1.11] Template class basic_fstream  /**   *  @brief  Controlling intput and output for files.   *   *  This class supports reading from and writing to named files, using   *  the inherited functions from std::basic_iostream.  To control the   *  associated sequence, an instance of std::basic_filebuf is used, which   *  this page refers to as @c sb.  */  template<typename _CharT, typename _Traits>    class basic_fstream : public basic_iostream<_CharT, _Traits>    {    public:      // Types:      typedef _CharT 					char_type;      typedef _Traits 					traits_type;      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_filebuf<char_type, traits_type> 	__filebuf_type;      typedef basic_ios<char_type, traits_type>		__ios_type;      typedef basic_iostream<char_type, traits_type>	__iostream_type;    private:      __filebuf_type	_M_filebuf;    public:      // Constructors/destructor:      /**       *  @brief  Default constructor.       *       *  Initializes @c sb using its default constructor, and passes       *  @c &sb to the base class initializer.  Does not open any files       *  (you haven't given it a filename to open).      */      basic_fstream()      : __iostream_type(), _M_filebuf()      { this->init(&_M_filebuf); }      /**       *  @brief  Create an input/output file stream.       *  @param  s  Null terminated string specifying the filename.       *  @param  mode  Open file in specified mode (see std::ios_base).       *       *  Tip:  When using std::string to hold the filename, you must use       *  .c_str() before passing it to this constructor.      */      explicit      basic_fstream(const char* __s,		    ios_base::openmode __mode = ios_base::in | ios_base::out)      : __iostream_type(NULL), _M_filebuf()      {	this->init(&_M_filebuf);	this->open(__s, __mode);      }      /**       *  @brief  The destructor does nothing.       *       *  The file is closed by the filebuf object, not the formatting       *  stream.      */      ~basic_fstream()      { }      // Members:      /**       *  @brief  Accessing the underlying buffer.       *  @return  The current basic_filebuf buffer.       *       *  This hides both signatures of std::basic_ios::rdbuf().      */      __filebuf_type*      rdbuf() const      { return const_cast<__filebuf_type*>(&_M_filebuf); }      /**       *  @brief  Wrapper to test for an open file.       *  @return  @c rdbuf()->is_open()      */      bool      is_open()      { return _M_filebuf.is_open(); }      // _GLIBCXX_RESOLVE_LIB_DEFECTS      // 365. Lack of const-qualification in clause 27      bool      is_open() const      { return _M_filebuf.is_open(); }      /**       *  @brief  Opens an external file.       *  @param  s  The name of the file.       *  @param  mode  The open mode flags.       *       *  Calls @c std::basic_filebuf::open(s,mode).  If that       *  function fails, @c failbit is set in the stream's error state.       *       *  Tip:  When using std::string to hold the filename, you must use       *  .c_str() before passing it to this constructor.      */      void      open(const char* __s,	   ios_base::openmode __mode = ios_base::in | ios_base::out)      {	if (!_M_filebuf.open(__s, __mode))	  this->setstate(ios_base::failbit);	else	  // _GLIBCXX_RESOLVE_LIB_DEFECTS	  // 409. Closing an fstream should clear error state	  this->clear();      }      /**       *  @brief  Close the file.       *       *  Calls @c std::basic_filebuf::close().  If that function       *  fails, @c failbit is set in the stream's error state.      */      void      close()      {	if (!_M_filebuf.close())	  this->setstate(ios_base::failbit);      }    };} // namespace std#ifndef _GLIBCXX_EXPORT_TEMPLATE# include <bits/fstream.tcc>#endif#endif /* _GLIBCXX_FSTREAM */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -