📄 istream
字号:
class _Traits> inline
void swap(basic_istream<_Elem, _Traits>& _Left,
basic_istream<_Elem, _Traits>& _Right)
{ // swap _Left and _Right basic_istreams
_Left.swap(_Right);
}
#ifndef _NATIVE_WCHAR_T_DEFINED
/* NOTE:
If you are not using native wchar_t, the following explicit
specialization will mask the member function (above) that treats
an unsigned short as an integer.
To read or write unsigned shorts as integers with wchar_t streams,
make wchar_t a native type with the command line option /Zc:wchar_t.
*/
template<> inline
basic_istream<unsigned short, char_traits<unsigned short> >&
__CLR_OR_THIS_CALL basic_istream<unsigned short,
char_traits<unsigned short> >::operator>>(unsigned short& _Ch)
{ // extract a character
typedef char_traits<unsigned short> _Traits;
int_type _Meta = 0;
ios_base::iostate _State = ios_base::goodbit;
const sentry _Ok(*this, true);
if (_Ok)
{ // state okay, extract a character
_TRY_IO_BEGIN
_Meta = _Myios::rdbuf()->sgetc();
if (_Traits::eq_int_type(_Traits::eof(), _Meta))
_State |= ios_base::eofbit | ios_base::failbit; // end of file
else
_Ch = _Myios::rdbuf()->sbumpc();
_CATCH_IO_END
}
_Myios::setstate(_State);
return (*this);
}
#endif /* _NATIVE_WCHAR_T_DEFINED */
#if defined(_DLL_CPPLIB) && !defined(_M_CEE_PURE)
#ifdef __FORCE_INSTANCE
template class _CRTIMP2_PURE basic_istream<char,
char_traits<char> >;
template class _CRTIMP2_PURE basic_istream<wchar_t,
char_traits<wchar_t> >;
#ifdef _CRTBLD_NATIVE_WCHAR_T
template class _CRTIMP2_PURE basic_istream<unsigned short,
char_traits<unsigned short> >;
#endif /* _CRTBLD_NATIVE_WCHAR_T */
#endif /* __FORCE_INSTANCE */
#endif /* defined(_DLL_CPPLIB) etc. */
// TEMPLATE CLASS basic_iostream
template<class _Elem,
class _Traits>
class basic_iostream
: public basic_istream<_Elem, _Traits>,
public basic_ostream<_Elem, _Traits>
{ // control insertions and extractions from a stream buffer
public:
typedef basic_iostream<_Elem, _Traits> _Myt;
typedef basic_istream<_Elem, _Traits> _Myis;
typedef basic_ostream<_Elem, _Traits> _Myos;
typedef basic_ios<_Elem, _Traits> _Myios;
typedef _Elem char_type;
typedef _Traits traits_type;
typedef typename _Traits::int_type int_type;
typedef typename _Traits::pos_type pos_type;
typedef typename _Traits::off_type off_type;
explicit __CLR_OR_THIS_CALL basic_iostream(basic_streambuf<_Elem, _Traits> *_Strbuf)
: _Myis(_Strbuf, false),
_Myos(_Noinit, false)
{ // construct from stream buffer pointer
}
__CLR_OR_THIS_CALL basic_iostream(_Myt&& _Right)
: _Myis(_Right.rdbuf(), false),
_Myos(_Noinit, false)
{ // construct by moving _Right
_Myios::init();
_Myios::move(_STD forward<_Myt>(_Right));
}
_Myt& __CLR_OR_THIS_CALL operator=(_Myt&& _Right)
{ // move from _Right
this->swap(_Right);
return (*this);
}
void __CLR_OR_THIS_CALL swap(_Myt& _Right)
{ // swap with _Right
if (this != &_Right)
_Myios::swap(_Right);
}
virtual __CLR_OR_THIS_CALL ~basic_iostream()
{ // destroy the object
}
};
// basic_iostream TEMPLATE OPERATORS
template<class _Elem,
class _Traits> inline
void swap(basic_iostream<_Elem, _Traits>& _Left,
basic_iostream<_Elem, _Traits>& _Right)
{ // swap _Left and _Right basic_iostreams
_Left.swap(_Right);
}
#if defined(_DLL_CPPLIB) && !defined(_M_CEE_PURE)
#ifdef __FORCE_INSTANCE
template class _CRTIMP2_PURE basic_iostream<char, char_traits<char> >;
template class _CRTIMP2_PURE basic_iostream<wchar_t, char_traits<wchar_t> >;
#ifdef _CRTBLD_NATIVE_WCHAR_T
template class _CRTIMP2_PURE basic_iostream<unsigned short,
char_traits<unsigned short> >;
#endif /* _CRTBLD_NATIVE_WCHAR_T */
#endif /* __FORCE_INSTANCE */
#endif /* defined(_DLL_CPPLIB) etc. */
// EXTRACTORS
template<class _Elem,
class _Traits> inline
basic_istream<_Elem, _Traits>& operator>>(
basic_istream<_Elem, _Traits> && _Istr, _Elem *_Str)
{ // extract NTBS
_DEBUG_POINTER(_Str);
typedef basic_istream<_Elem, _Traits> _Myis;
typedef ctype<_Elem> _Ctype;
ios_base::iostate _State = ios_base::goodbit;
_Elem *_Str0 = _Str;
const typename _Myis::sentry _Ok(_Istr);
if (_Ok)
{ // state okay, extract characters
const _Ctype& _Ctype_fac = _USE(_Istr.getloc(), _Ctype);
_TRY_IO_BEGIN
streamsize _Count = 0 < _Istr.width() ? _Istr.width() : INT_MAX;
typename _Myis::int_type _Meta = _Istr.rdbuf()->sgetc();
_Elem _Ch;
for (; 0 < --_Count; _Meta = _Istr.rdbuf()->snextc())
if (_Traits::eq_int_type(_Traits::eof(), _Meta))
{ // end of file, quit
_State |= ios_base::eofbit;
break;
}
else if (_Ctype_fac.is(_Ctype::space,
_Ch = _Traits::to_char_type(_Meta))
|| _Ch == _Elem())
break; // whitespace or nul, quit
else
*_Str++ = _Traits::to_char_type(_Meta); // add it to string
_CATCH_IO_(_Istr)
}
*_Str = _Elem(); // add terminating null character
_Istr.width(0);
_Istr.setstate(_Str == _Str0 ? _State | ios_base::failbit : _State);
return (_Istr);
}
template<class _Elem,
class _Traits> inline
basic_istream<_Elem, _Traits>& operator>>(
basic_istream<_Elem, _Traits> && _Istr, _Elem& _Ch)
{ // extract a character
typedef basic_istream<_Elem, _Traits> _Myis;
typename _Myis::int_type _Meta;
ios_base::iostate _State = ios_base::goodbit;
const typename _Myis::sentry _Ok(_Istr);
if (_Ok)
{ // state okay, extract characters
_TRY_IO_BEGIN
_Meta = _Istr.rdbuf()->sbumpc();
if (_Traits::eq_int_type(_Traits::eof(), _Meta))
_State |= ios_base::eofbit | ios_base::failbit; // end of file
else
_Ch = _Traits::to_char_type(_Meta); // got a character
_CATCH_IO_(_Istr)
}
_Istr.setstate(_State);
return (_Istr);
}
template<class _Traits> inline
basic_istream<char, _Traits>& operator>>(
basic_istream<char, _Traits> && _Istr, signed char *_Str)
{ // extract a signed char NTBS
return (_Istr >> (char *)_Str);
}
template<class _Traits> inline
basic_istream<char, _Traits>& operator>>(
basic_istream<char, _Traits> && _Istr, signed char& _Ch)
{ // extract a signed char
return (_Istr >> (char&)_Ch);
}
template<class _Traits> inline
basic_istream<char, _Traits>& operator>>(
basic_istream<char, _Traits> && _Istr, unsigned char *_Str)
{ // extract an unsigned char NTBS
return (_Istr >> (char *)_Str);
}
template<class _Traits> inline
basic_istream<char, _Traits>& operator>>(
basic_istream<char, _Traits> && _Istr, unsigned char& _Ch)
{ // extract an unsigned char
return (_Istr >> (char&)_Ch);
}
template<class _Elem,
class _Traits> inline
basic_istream<_Elem, _Traits>& operator>>(
basic_istream<_Elem, _Traits>& _Istr, _Elem *_Str)
{ // extract NTBS
return (_STD move(_Istr) >> _Str);
}
template<class _Elem,
class _Traits> inline
basic_istream<_Elem, _Traits>& operator>>(
basic_istream<_Elem, _Traits>& _Istr, _Elem& _Ch)
{ // extract a character
return (_STD move(_Istr) >> _Ch);
}
template<class _Traits> inline
basic_istream<char, _Traits>& operator>>(
basic_istream<char, _Traits>& _Istr, signed char *_Str)
{ // extract a signed char NTBS
return (_STD move(_Istr) >> (char *)_Str);
}
template<class _Traits> inline
basic_istream<char, _Traits>& operator>>(
basic_istream<char, _Traits>& _Istr, signed char& _Ch)
{ // extract a signed char
return (_STD move(_Istr) >> (char&)_Ch);
}
template<class _Traits> inline
basic_istream<char, _Traits>& operator>>(
basic_istream<char, _Traits>& _Istr, unsigned char *_Str)
{ // extract an unsigned char NTBS
return (_STD move(_Istr) >> (char *)_Str);
}
template<class _Traits> inline
basic_istream<char, _Traits>& operator>>(
basic_istream<char, _Traits>& _Istr, unsigned char& _Ch)
{ // extract an unsigned char
return (_STD move(_Istr) >> (char&)_Ch);
}
template<class _Elem,
class _Traits,
class _Ty> inline
basic_istream<_Elem, _Traits>&
operator>>(basic_istream<_Elem, _Traits>&& _Istr, _Ty& _Val)
{ // extract from rvalue stream
return (_Istr >> _Val);
}
// MANIPULATORS
template<class _Elem,
class _Traits> inline
basic_istream<_Elem, _Traits>&
__CLRCALL_OR_CDECL ws(basic_istream<_Elem, _Traits>& _Istr)
{ // consume whitespace
typedef basic_istream<_Elem, _Traits> _Myis;
typedef ctype<_Elem> _Ctype;
if (!_Istr.eof())
{ // not at eof, okay to construct sentry and skip
ios_base::iostate _State = ios_base::goodbit;
const typename _Myis::sentry _Ok(_Istr, true);
if (_Ok)
{ // state okay, extract characters
const _Ctype& _Ctype_fac = _USE(_Istr.getloc(), _Ctype);
_TRY_IO_BEGIN
for (typename _Traits::int_type _Meta = _Istr.rdbuf()->sgetc(); ;
_Meta = _Istr.rdbuf()->snextc())
if (_Traits::eq_int_type(_Traits::eof(), _Meta))
{ // end of file, quit
_State |= ios_base::eofbit;
break;
}
else if (!_Ctype_fac.is(_Ctype::space,
_Traits::to_char_type(_Meta)))
break; // not whitespace, quit
_CATCH_IO_(_Istr)
}
_Istr.setstate(_State);
}
return (_Istr);
}
_CRTIMP2_PURE inline basic_istream<char, char_traits<char> >&
__CLRCALL_OR_CDECL ws(basic_istream<char, char_traits<char> >& _Istr)
{ // consume whitespace
typedef char _Elem;
typedef char_traits<_Elem> _Traits;
if (!_Istr.eof())
{ // not at eof, okay to construct sentry and skip
ios_base::iostate _State = ios_base::goodbit;
const basic_istream<_Elem, _Traits>::sentry _Ok(_Istr, true);
if (_Ok)
{ // state okay, use facet to extract
const ctype<_Elem>& _Ctype_fac =
_USE(_Istr.getloc(), ctype<_Elem>);
_TRY_IO_BEGIN
for (_Traits::int_type _Meta = _Istr.rdbuf()->sgetc(); ;
_Meta = _Istr.rdbuf()->snextc())
if (_Traits::eq_int_type(_Traits::eof(), _Meta))
{ // end of file, quit
_State |= ios_base::eofbit;
break;
}
else if (!_Ctype_fac.is(ctype<_Elem>::space,
_Traits::to_char_type(_Meta)))
break; // not whitespace, quit
_CATCH_IO_(_Istr)
}
_Istr.setstate(_State);
}
return (_Istr);
}
_CRTIMP2_PURE inline basic_istream<wchar_t, char_traits<wchar_t> >&
__CLRCALL_OR_CDECL ws(basic_istream<wchar_t, char_traits<wchar_t> >& _Istr)
{ // consume whitespace
typedef wchar_t _Elem;
typedef char_traits<_Elem> _Traits;
if (!_Istr.eof())
{ // not at eof, okay to construct sentry and skip
ios_base::iostate _State = ios_base::goodbit;
const basic_istream<_Elem, _Traits>::sentry _Ok(_Istr, true);
if (_Ok)
{ // state okay, use facet to extract
const ctype<_Elem>& _Ctype_fac =
_USE(_Istr.getloc(), ctype<_Elem>);
_TRY_IO_BEGIN
for (_Traits::int_type _Meta = _Istr.rdbuf()->sgetc(); ;
_Meta = _Istr.rdbuf()->snextc())
if (_Traits::eq_int_type(_Traits::eof(), _Meta))
{ // end of file, quit
_State |= ios_base::eofbit;
break;
}
else if (!_Ctype_fac.is(ctype<_Elem>::space,
_Traits::to_char_type(_Meta)))
break; // not whitespace, quit
_CATCH_IO_(_Istr)
}
_Istr.setstate(_State);
}
return (_Istr);
}
#ifdef _NATIVE_WCHAR_T_DEFINED
_CRTIMP2_PURE inline basic_istream<unsigned short, char_traits<unsigned short> >&
__CLRCALL_OR_CDECL ws(basic_istream<unsigned short, char_traits<unsigned short> >& _Istr)
{ // consume whitespace
typedef unsigned short _Elem;
typedef char_traits<_Elem> _Traits;
if (!_Istr.eof())
{ // not at eof, okay to construct sentry and skip
ios_base::iostate _State = ios_base::goodbit;
const basic_istream<_Elem, _Traits>::sentry _Ok(_Istr, true);
if (_Ok)
{ // state okay, use facet to extract
const ctype<_Elem>& _Ctype_fac =
_USE(_Istr.getloc(), ctype<_Elem>);
_TRY_IO_BEGIN
for (_Traits::int_type _Meta = _Istr.rdbuf()->sgetc(); ;
_Meta = _Istr.rdbuf()->snextc())
if (_Traits::eq_int_type(_Traits::eof(), _Meta))
{ // end of file, quit
_State |= ios_base::eofbit;
break;
}
else if (!_Ctype_fac.is(ctype<_Elem>::space,
_Traits::to_char_type(_Meta)))
break; // not whitespace, quit
_CATCH_IO_(_Istr)
}
_Istr.setstate(_State);
}
return (_Istr);
}
#endif /* _NATIVE_WCHAR_T_DEFINED */
_STD_END
#pragma warning(pop)
#pragma pack(pop)
#endif /* RC_INVOKED */
#endif /* _ISTREAM_ */
/*
* Copyright (c) 1992-2009 by P.J. Plauger. ALL RIGHTS RESERVED.
* Consult your license regarding permissions and restrictions.
V5.20:0009 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -