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

📄 istream.tcc

📁 linux下编程用 编译软件
💻 TCC
📖 第 1 页 / 共 3 页
字号:
		__err |= ios_base::failbit;	    }	  catch(...)	    { this->_M_setstate(ios_base::failbit); }	}      else if (!__sbout)	__err |= ios_base::failbit;      if (__err)	this->setstate(__err);      return *this;    }  template<typename _CharT, typename _Traits>    typename basic_istream<_CharT, _Traits>::int_type    basic_istream<_CharT, _Traits>::    get(void)    {      const int_type __eof = traits_type::eof();      int_type __c = __eof;      _M_gcount = 0;      ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);      sentry __cerb(*this, true);      if (__cerb)	{	  try	    {	      __c = this->rdbuf()->sbumpc();	      // 27.6.1.1 paragraph 3	      if (!traits_type::eq_int_type(__c, __eof))		_M_gcount = 1;	      else		__err |= ios_base::eofbit;	    }	  catch(...)	    { this->_M_setstate(ios_base::badbit); }	}      if (!_M_gcount)	__err |= ios_base::failbit;      if (__err)	this->setstate(__err);      return __c;    }  template<typename _CharT, typename _Traits>    basic_istream<_CharT, _Traits>&    basic_istream<_CharT, _Traits>::    get(char_type& __c)    {      _M_gcount = 0;      ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);      sentry __cerb(*this, true);      if (__cerb)	{	  try	    {	      const int_type __cb = this->rdbuf()->sbumpc();	      // 27.6.1.1 paragraph 3	      if (!traits_type::eq_int_type(__cb, traits_type::eof()))		{		  _M_gcount = 1;		  __c = traits_type::to_char_type(__cb);		}	      else		__err |= ios_base::eofbit;	    }	  catch(...)	    { this->_M_setstate(ios_base::badbit); }	}      if (!_M_gcount)	__err |= ios_base::failbit;      if (__err)	this->setstate(__err);      return *this;    }  template<typename _CharT, typename _Traits>    basic_istream<_CharT, _Traits>&    basic_istream<_CharT, _Traits>::    get(char_type* __s, streamsize __n, char_type __delim)    {      _M_gcount = 0;      ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);      sentry __cerb(*this, true);      if (__cerb)	{	  try	    {	      const int_type __idelim = traits_type::to_int_type(__delim);	      const int_type __eof = traits_type::eof();	      __streambuf_type* __sb = this->rdbuf();	      int_type __c = __sb->sgetc();	      while (_M_gcount + 1 < __n		     && !traits_type::eq_int_type(__c, __eof)		     && !traits_type::eq_int_type(__c, __idelim))		{		  *__s++ = traits_type::to_char_type(__c);		  ++_M_gcount;		  __c = __sb->snextc();		}	      if (traits_type::eq_int_type(__c, __eof))		__err |= ios_base::eofbit;	    }	  catch(...)	    { this->_M_setstate(ios_base::badbit); }	}      // _GLIBCXX_RESOLVE_LIB_DEFECTS      // 243. get and getline when sentry reports failure.      if (__n > 0)	*__s = char_type();      if (!_M_gcount)	__err |= ios_base::failbit;      if (__err)	this->setstate(__err);      return *this;    }  template<typename _CharT, typename _Traits>    basic_istream<_CharT, _Traits>&    basic_istream<_CharT, _Traits>::    get(__streambuf_type& __sb, char_type __delim)    {      _M_gcount = 0;      ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);      sentry __cerb(*this, true);      if (__cerb)	{	  try	    {	      const int_type __idelim = traits_type::to_int_type(__delim);	      const int_type __eof = traits_type::eof();	      __streambuf_type* __this_sb = this->rdbuf();	      int_type __c = __this_sb->sgetc();	      char_type __c2 = traits_type::to_char_type(__c);	      while (!traits_type::eq_int_type(__c, __eof)		     && !traits_type::eq_int_type(__c, __idelim)		     && !traits_type::eq_int_type(__sb.sputc(__c2), __eof))		{		  ++_M_gcount;		  __c = __this_sb->snextc();		  __c2 = traits_type::to_char_type(__c);		}	      if (traits_type::eq_int_type(__c, __eof))		__err |= ios_base::eofbit;	    }	  catch(...)	    { this->_M_setstate(ios_base::badbit); }	}      if (!_M_gcount)	__err |= ios_base::failbit;      if (__err)	this->setstate(__err);      return *this;    }  template<typename _CharT, typename _Traits>    basic_istream<_CharT, _Traits>&    basic_istream<_CharT, _Traits>::    getline(char_type* __s, streamsize __n, char_type __delim)    {      _M_gcount = 0;      ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);      sentry __cerb(*this, true);      if (__cerb)        {          try            {              const int_type __idelim = traits_type::to_int_type(__delim);              const int_type __eof = traits_type::eof();              __streambuf_type* __sb = this->rdbuf();              int_type __c = __sb->sgetc();              while (_M_gcount + 1 < __n                     && !traits_type::eq_int_type(__c, __eof)                     && !traits_type::eq_int_type(__c, __idelim))                {                  *__s++ = traits_type::to_char_type(__c);                  __c = __sb->snextc();                  ++_M_gcount;                }              if (traits_type::eq_int_type(__c, __eof))                __err |= ios_base::eofbit;              else                {                  if (traits_type::eq_int_type(__c, __idelim))                    {                      __sb->sbumpc();                      ++_M_gcount;                    }                  else                    __err |= ios_base::failbit;                }            }          catch(...)            { this->_M_setstate(ios_base::badbit); }        }      // _GLIBCXX_RESOLVE_LIB_DEFECTS      // 243. get and getline when sentry reports failure.      if (__n > 0)	*__s = char_type();      if (!_M_gcount)        __err |= ios_base::failbit;      if (__err)        this->setstate(__err);      return *this;    }  // We provide three overloads, since the first two are much simpler  // than the general case. Also, the latter two can thus adopt the  // same "batchy" strategy used by getline above.  template<typename _CharT, typename _Traits>    basic_istream<_CharT, _Traits>&    basic_istream<_CharT, _Traits>::    ignore(void)    {      _M_gcount = 0;      sentry __cerb(*this, true);      if (__cerb)	{	  ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);	  try	    {	      const int_type __eof = traits_type::eof();	      __streambuf_type* __sb = this->rdbuf();	      if (traits_type::eq_int_type(__sb->sbumpc(), __eof))		__err |= ios_base::eofbit;	      else		_M_gcount = 1;	    }	  catch(...)	    { this->_M_setstate(ios_base::badbit); }	  if (__err)	    this->setstate(__err);	}      return *this;    }  template<typename _CharT, typename _Traits>    basic_istream<_CharT, _Traits>&    basic_istream<_CharT, _Traits>::    ignore(streamsize __n)    {      _M_gcount = 0;      sentry __cerb(*this, true);      if (__cerb && __n > 0)        {          ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);          try            {              const int_type __eof = traits_type::eof();              __streambuf_type* __sb = this->rdbuf();              int_type __c = __sb->sgetc();	      // N.B. On LFS-enabled platforms streamsize is still 32 bits	      // wide: if we want to implement the standard mandated behavior	      // for n == max() (see 27.6.1.3/24) we are at risk of signed	      // integer overflow: thus these contortions. Also note that,	      // by definition, when more than 2G chars are actually ignored,	      // _M_gcount (the return value of gcount, that is) cannot be	      // really correct, being unavoidably too small.	      bool __large_ignore = false;	      while (true)		{		  while (_M_gcount < __n			 && !traits_type::eq_int_type(__c, __eof))		    {		      ++_M_gcount;		      __c = __sb->snextc();		    }		  if (__n == numeric_limits<streamsize>::max()		      && !traits_type::eq_int_type(__c, __eof))		    {		      _M_gcount = numeric_limits<streamsize>::min();		      __large_ignore = true;		    }		  else		    break;		}	      if (__large_ignore)		_M_gcount = numeric_limits<streamsize>::max();	      if (traits_type::eq_int_type(__c, __eof))                __err |= ios_base::eofbit;            }          catch(...)            { this->_M_setstate(ios_base::badbit); }          if (__err)            this->setstate(__err);        }      return *this;    }  template<typename _CharT, typename _Traits>    basic_istream<_CharT, _Traits>&    basic_istream<_CharT, _Traits>::    ignore(streamsize __n, int_type __delim)    {      _M_gcount = 0;      sentry __cerb(*this, true);      if (__cerb && __n > 0)        {          ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);          try            {              const int_type __eof = traits_type::eof();              __streambuf_type* __sb = this->rdbuf();              int_type __c = __sb->sgetc();	      // See comment above.	      bool __large_ignore = false;	      while (true)		{		  while (_M_gcount < __n			 && !traits_type::eq_int_type(__c, __eof)			 && !traits_type::eq_int_type(__c, __delim))		    {		      ++_M_gcount;		      __c = __sb->snextc();		    }		  if (__n == numeric_limits<streamsize>::max()		      && !traits_type::eq_int_type(__c, __eof)		      && !traits_type::eq_int_type(__c, __delim))		    {		      _M_gcount = numeric_limits<streamsize>::min();		      __large_ignore = true;		    }		  else		    break;		}	      if (__large_ignore)		_M_gcount = numeric_limits<streamsize>::max();              if (traits_type::eq_int_type(__c, __eof))                __err |= ios_base::eofbit;	      else if (traits_type::eq_int_type(__c, __delim))		{		  if (_M_gcount < numeric_limits<streamsize>::max())		    ++_M_gcount;		  __sb->sbumpc();		}            }          catch(...)            { this->_M_setstate(ios_base::badbit); }          if (__err)            this->setstate(__err);        }      return *this;    }  template<typename _CharT, typename _Traits>    typename basic_istream<_CharT, _Traits>::int_type    basic_istream<_CharT, _Traits>::    peek(void)    {      int_type __c = traits_type::eof();      _M_gcount = 0;      sentry __cerb(*this, true);      if (__cerb)	{	  ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);	  try	    {	      __c = this->rdbuf()->sgetc();	      if (traits_type::eq_int_type(__c, traits_type::eof()))		__err |= ios_base::eofbit;	    }	  catch(...)	    { this->_M_setstate(ios_base::badbit); }	  if (__err)	    this->setstate(__err);	}      return __c;    }  template<typename _CharT, typename _Traits>    basic_istream<_CharT, _Traits>&    basic_istream<_CharT, _Traits>::    read(char_type* __s, streamsize __n)    {      _M_gcount = 0;      sentry __cerb(*this, true);      if (__cerb)	{	  ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);	  try	    {	      _M_gcount = this->rdbuf()->sgetn(__s, __n);	      if (_M_gcount != __n)		__err |= (ios_base::eofbit | ios_base::failbit);	    }	  catch(...)	    { this->_M_setstate(ios_base::badbit); }	  if (__err)	    this->setstate(__err);	}      return *this;    }  template<typename _CharT, typename _Traits>    streamsize    basic_istream<_CharT, _Traits>::    readsome(char_type* __s, streamsize __n)    {      _M_gcount = 0;      sentry __cerb(*this, true);      if (__cerb)	{	  ios_base::iostate __err = ios_base::iostate(ios_base::goodbit);	  try	    {	      // Cannot compare int_type with streamsize generically.	      const streamsize __num = this->rdbuf()->in_avail();	      if (__num > 0)		_M_gcount = this->rdbuf()->sgetn(__s, std::min(__num, __n));	      else if (__num == -1)		__err |= ios_base::eofbit;	    }	  catch(...)	    { this->_M_setstate(ios_base::badbit); }	  if (__err)	    this->setstate(__err);	}      return _M_gcount;    }

⌨️ 快捷键说明

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