1 // istream standard header
2 #pragma once
3 #ifndef _ISTREAM_
4 #define _ISTREAM_
5 #ifndef RC_INVOKED
6 #include <ostream>
7
8 #ifdef _MSC_VER
9  #pragma pack(push,_CRT_PACKING)
10  #pragma warning(push,3)
11 #endif  /* _MSC_VER */
12
13 _STD_BEGIN
14
15         // TEMPLATE CLASS basic_istream
16 template<class _Elem,
17     class _Traits>
18     class basic_istream
19         : virtual public basic_ios<_Elem, _Traits>
20     {    // control extractions from a stream buffer
21 public:
22     typedef basic_istream<_Elem, _Traits> _Myt;
23     typedef basic_ios<_Elem, _Traits> _Myios;
24     typedef basic_streambuf<_Elem, _Traits> _Mysb;
25     typedef istreambuf_iterator<_Elem, _Traits> _Iter;
26     typedef ctype<_Elem> _Ctype;
27     typedef num_get<_Elem, _Iter> _Nget;
28
29
30     explicit __CLR_OR_THIS_CALL basic_istream(_Mysb *_Strbuf, bool _Isstd = false)
31         : _Chcount(0)
32         {    // construct from stream buffer pointer
33         _Myios::init(_Strbuf, _Isstd);
34         }
35
36     __CLR_OR_THIS_CALL basic_istream(_Uninitialized)
37         {    // construct uninitialized
38         ios_base::_Addstd(this);
39         }
40
41     virtual __CLR_OR_THIS_CALL ~basic_istream()
42         {    // destroy the object
43         }
44
45     typedef typename _Traits::int_type int_type;
46     typedef typename _Traits::pos_type pos_type;
47     typedef typename _Traits::off_type off_type;
48
49         // TEMPLATE CLASS sentry
50     class _Sentry_base
51         {    // stores thread lock and reference to input stream
52     public:
53         __CLR_OR_THIS_CALL _Sentry_base(_Myt& _Istr)
54             : _Myistr(_Istr)
55             {    // lock the stream buffer, if there
56             if (_Myistr.rdbuf() != 0)
57                 _Myistr.rdbuf()->_Lock();
58             }
59
60         __CLR_OR_THIS_CALL ~_Sentry_base()
61             {    // destroy after unlocking
62             if (_Myistr.rdbuf() != 0)
63                 _Myistr.rdbuf()->_Unlock();
64             }
65
66         _Myt& _Myistr;    // the input stream, for _Unlock call at destruction
67         };
68
69     class sentry
70         : public _Sentry_base
71         {    // stores thread lock and result of _Ipfx call
72     public:
73         explicit __CLR_OR_THIS_CALL sentry(_Myt& _Istr, bool _Noskip = false)
74             : _Sentry_base(_Istr)
75             {    // construct locking and calling _Ipfx
76             _Ok = this->_Myistr._Ipfx(_Noskip);
77             }
78
79         __CLR_OR_THIS_CALL operator bool() const
80             {    // test if _Ipfx succeeded
81             return (_Ok);
82             }
83
84     private:
85         __CLR_OR_THIS_CALL sentry(const sentry&);    // not defined
86         sentry& __CLR_OR_THIS_CALL operator=(const sentry&);    // not defined
87
88         bool _Ok;    // true if _Ipfx succeeded at construction
89         };
90
91     bool __CLR_OR_THIS_CALL _Ipfx(bool _Noskip = false)
92         {    // test stream state and skip whitespace as needed
93         if (ios_base::good())
94             {    // state okay, flush tied stream and skip whitespace
95             if (_Myios::tie() != 0)
96                 _Myios::tie()->flush();
97
98             if (!_Noskip && ios_base::flags() & ios_base::skipws)
99                 {    // skip whitespace
100                 const _Ctype& _Ctype_fac = _USE(ios_base::getloc(), _Ctype);
101
102                 _TRY_IO_BEGIN
103                 int_type _Meta = _Myios::rdbuf()->sgetc();
104
105                 for (; ; _Meta = _Myios::rdbuf()->snextc())
106                     if (_Traits::eq_int_type(_Traits::eof(), _Meta))
107                         {    // end of file, quit
108                         _Myios::setstate(ios_base::eofbit);
109                         break;
110                         }
111                     else if (!_Ctype_fac.is(_Ctype::space,
112                         _Traits::to_char_type(_Meta)))
113                         break;    // not whitespace, quit
114                 _CATCH_IO_END
115                 }
116
117             if (ios_base::good())
118                 return (true);
119             }
120         _Myios::setstate(ios_base::failbit);
121         return (false);
122         }
123
124     bool __CLR_OR_THIS_CALL ipfx(bool _Noskip = false)
125         {    // test stream state and skip whitespace as needed (retained)
126         return _Ipfx(_Noskip);
127         }
128
129     void __CLR_OR_THIS_CALL isfx()
130         {    // perform any wrapup (retained)
131         }
132
133 #ifdef _M_CEE_PURE
134     _Myt& __CLR_OR_THIS_CALL operator>>(_Myt& (__clrcall *_Pfn)(_Myt&))
135         {    // call basic_istream manipulator
136         _DEBUG_POINTER(_Pfn);
137         return ((*_Pfn)(*this));
138         }
139
140     _Myt& __CLR_OR_THIS_CALL operator>>(_Myios& (__clrcall *_Pfn)(_Myios&))
141         {    // call basic_ios manipulator
142         _DEBUG_POINTER(_Pfn);
143         (*_Pfn)(*(_Myios *)this);
144         return (*this);
145         }
146
147     _Myt& __CLR_OR_THIS_CALL operator>>(ios_base& (__clrcall *_Pfn)(ios_base&))
148         {    // call ios_base manipulator
149         _DEBUG_POINTER(_Pfn);
150         (*_Pfn)(*(ios_base *)this);
151         return (*this);
152         }
153 #endif
154
155     _Myt& __CLR_OR_THIS_CALL operator>>(_Myt& (__cdecl *_Pfn)(_Myt&))
156         {    // call basic_istream manipulator
157         _DEBUG_POINTER(_Pfn);
158         return ((*_Pfn)(*this));
159         }
160
161     _Myt& __CLR_OR_THIS_CALL operator>>(_Myios& (__cdecl *_Pfn)(_Myios&))
162         {    // call basic_ios manipulator
163         _DEBUG_POINTER(_Pfn);
164         (*_Pfn)(*(_Myios *)this);
165         return (*this);
166         }
167
168     _Myt& __CLR_OR_THIS_CALL operator>>(ios_base& (__cdecl *_Pfn)(ios_base&))
169         {    // call ios_base manipulator
170         _DEBUG_POINTER(_Pfn);
171         (*_Pfn)(*(ios_base *)this);
172         return (*this);
173         }
174
175     _Myt& __CLR_OR_THIS_CALL operator>>(_Bool& _Val)
176         {    // extract a boolean
177         ios_base::iostate _State = ios_base::goodbit;
178         const sentry _Ok(*this);
179
180         if (_Ok)
181             {    // state okay, use facet to extract
182             const _Nget& _Nget_fac = _USE(ios_base::getloc(), _Nget);
183
184             _TRY_IO_BEGIN
185             _Nget_fac.get(_Iter(_Myios::rdbuf()), _Iter(0),
186                 *this, _State, _Val);
187             _CATCH_IO_END
188             }
189
190         _Myios::setstate(_State);
191         return (*this);
192         }
193
194     _Myt& __CLR_OR_THIS_CALL operator>>(short& _Val)
195         {    // extract a short
196         ios_base::iostate _State = ios_base::goodbit;
197         const sentry _Ok(*this);
198
199         if (_Ok)
200             {    // state okay, use facet to extract
201             long _Tmp = 0;
202             const _Nget& _Nget_fac = _USE(ios_base::getloc(), _Nget);
203
204             _TRY_IO_BEGIN
205             _Nget_fac.get(_Iter(_Myios::rdbuf()), _Iter(0),
206                 *this, _State, _Tmp);
207             _CATCH_IO_END
208
209             if (_State & ios_base::failbit
210                 || _Tmp < SHRT_MIN || SHRT_MAX < _Tmp)
211                 _State |= ios_base::failbit;
212             else
213                 _Val = (short)_Tmp;
214             }
215
216         _Myios::setstate(_State);
217         return (*this);
218         }
219
220              /*  Note that if your stream is wchar_t, and you are not using native wchar_t
221                     Then this operation will be unavailable as there is an explicit 
222                     specialisation further down this file that is designed to treat an 
223                     unsigned short as a character.
224
225                     If you wish to read or write unsigned shorts to wchar_t streams, you should 
226                     consider making wchar_t a native type by turning on /Zc:wchar_t
227              */
228     _Myt& __CLR_OR_THIS_CALL operator>>(unsigned short& _Val)
229         {    // extract an unsigned short
230         ios_base::iostate _State = ios_base::goodbit;
231         const sentry _Ok(*this);
232
233         if (_Ok)
234             {    // state okay, use facet to extract
235             const _Nget& _Nget_fac = _USE(ios_base::getloc(), _Nget);
236
237             _TRY_IO_BEGIN
238             _Nget_fac.get(_Iter(_Myios::rdbuf()), _Iter(0),
239                 *this, _State, _Val);
240             _CATCH_IO_END
241             }
242
243         _Myios::setstate(_State);
244         return (*this);
245         }
246
247     _Myt& __CLR_OR_THIS_CALL operator>>(int& _Val)
248         {    // extract an int
249         ios_base::iostate _State = ios_base::goodbit;
250         const sentry _Ok(*this);
251
252         if (_Ok)
253             {    // state okay, use facet to extract
254             long _Tmp = 0;
255             const _Nget& _Nget_fac = _USE(ios_base::getloc(), _Nget);
256
257             _TRY_IO_BEGIN
258             _Nget_fac.get(_Iter(_Myios::rdbuf()), _Iter(0),
259                 *this, _State, _Tmp);
260             _CATCH_IO_END
261
262             if (_State & ios_base::failbit
263                 || _Tmp < INT_MIN || INT_MAX < _Tmp)
264                 _State |= ios_base::failbit;
265             else
266                 _Val = _Tmp;
267             }
268
269         _Myios::setstate(_State);
270         return (*this);
271         }
272
273     _Myt& __CLR_OR_THIS_CALL operator>>(unsigned int& _Val)
274         {    // extract an unsigned int
275         ios_base::iostate _State = ios_base::goodbit;
276         const sentry _Ok(*this);
277         if (_Ok)
278             {    // state okay, use facet to extract
279             const _Nget& _Nget_fac = _USE(ios_base::getloc(), _Nget);
280
281             _TRY_IO_BEGIN
282             _Nget_fac.get(_Iter(_Myios::rdbuf()), _Iter(0),
283                 *this, _State, _Val);
284             _CATCH_IO_END
285             }
286
287         _Myios::setstate(_State);
288         return (*this);
289         }
290
291     _Myt& __CLR_OR_THIS_CALL operator>>(long& _Val)
292         {    // extract a long
293         ios_base::iostate _State = ios_base::goodbit;
294         const sentry _Ok(*this);
295
296         if (_Ok)
297             {    // state okay, use facet to extract
298             const _Nget& _Nget_fac = _USE(ios_base::getloc(), _Nget);
299             _TRY_IO_BEGIN
300             _Nget_fac.get(_Iter(_Myios::rdbuf()), _Iter(0),
301                 *this, _State, _Val);
302             _CATCH_IO_END
303             }
304
305         _Myios::setstate(_State);
306         return (*this);
307         }
308
309     _Myt& __CLR_OR_THIS_CALL operator>>(unsigned long __w64& _Val)
310         {    // extract an unsigned long
311         ios_base::iostate _State = ios_base::goodbit;
312         const sentry _Ok(*this);
313
314         if (_Ok)
315             {    // state okay, use facet to extract
316             const _Nget& _Nget_fac = _USE(ios_base::getloc(), _Nget);
317
318             _TRY_IO_BEGIN
319             _Nget_fac.get(_Iter(_Myios::rdbuf()), _Iter(0),
320                 *this, _State, _Val);
321             _CATCH_IO_END
322             }
323
324         _Myios::setstate(_State);
325         return (*this);
326         }
327
328  #ifdef _LONGLONG
329     _Myt& __CLR_OR_THIS_CALL operator>>(_LONGLONG& _Val)
330         {    // extract a long long
331         ios_base::iostate _State = ios_base::goodbit;
332         const sentry _Ok(*this);
333
334         if (_Ok)
335             {    // state okay, use facet to extract
336             const _Nget& _Nget_fac = _USE(ios_base::getloc(), _Nget);
337
338             _TRY_IO_BEGIN
339             _Nget_fac.get(_Iter(_Myios::rdbuf()), _Iter(0),
340                 *this, _State, _Val);
341             _CATCH_IO_END
342             }
343
344         _Myios::setstate(_State);
345         return (*this);
346         }
347
348     _Myt& __CLR_OR_THIS_CALL operator>>(_ULONGLONG& _Val)
349         {    // extract an  unsigned long long
350         ios_base::iostate _State = ios_base::goodbit;
351         const sentry _Ok(*this);
352         if (_Ok)
353             {    // state okay, use facet to extract
354             const _Nget& _Nget_fac = _USE(ios_base::getloc(), _Nget);
355
356             _TRY_IO_BEGIN
357             _Nget_fac.get(_Iter(_Myios::rdbuf()), _Iter(0),
358                 *this, _State, _Val);
359             _CATCH_IO_END
360             }
361
362         _Myios::setstate(_State);
363         return (*this);
364         }
365  #endif /* _LONGLONG */
366
367     _Myt& __CLR_OR_THIS_CALL operator>>(float& _Val)
368         {    // extract a float
369         ios_base::iostate _State = ios_base::goodbit;
370         const sentry _Ok(*this);
371
372         if (_Ok)
373             {    // state okay, use facet to extract
374             const _Nget& _Nget_fac = _USE(ios_base::getloc(), _Nget);
375
376             _TRY_IO_BEGIN
377             _Nget_fac.get(_Iter(_Myios::rdbuf()), _Iter(0),
378                 *this, _State, _Val);
Lines 379 ... 798 are skipped.
799         if (_Myios::rdbuf() == 0)
800             _Ans = -1;    // no buffer, fail
801         else if (_Myios::rdbuf()->pubsync() == -1)
802             {    // stream buffer sync failed, fail
803             _State |= ios_base::badbit;
804             _Ans = -1;
805             }
806         else
807             _Ans = 0;    // success
808
809         _Myios::setstate(_State);
810         return (_Ans);
811         }
812
813     _Myt& __CLR_OR_THIS_CALL seekg(pos_type _Pos)
814         {    // set input stream position to _Pos
815         if (!ios_base::fail()
816             && (off_type)_Myios::rdbuf()->pubseekpos(_Pos,
817                 ios_base::in) == _BADOFF)
818             _Myios::setstate(ios_base::failbit);
819         else
820             _Myios::clear();    // clear eofbit if set
821         return (*this);
822         }
823
824     _Myt& __CLR_OR_THIS_CALL seekg(off_type _Off, ios_base::seekdir _Way)
825         {    // change input stream position by _Off, according to _Way
826         if (!ios_base::fail()
827             && (off_type)_Myios::rdbuf()->pubseekoff(_Off, _Way,
828                 ios_base::in) == _BADOFF)
829             _Myios::setstate(ios_base::failbit);
830         else
831             _Myios::clear();    // clear eofbit if set
832         return (*this);
833         }
834
835     pos_type __CLR_OR_THIS_CALL tellg()
836         {    // return input stream position
837         if (!ios_base::fail())
838             return (_Myios::rdbuf()->pubseekoff(0,
839                 ios_base::cur, ios_base::in));
840         else
841             return (pos_type(_BADOFF));
842         }
843
844 private:
845     streamsize _Chcount;    // the character count
846     };
847
848 #ifndef _NATIVE_WCHAR_T_DEFINED
849 /*
850 This explicit template specialisation reads a single unicode character from the stream.
851
852 By default, the compiler treats wchar_t as if it were a typedef for unsigned short. This means
853 that we cannot distinguish between an unsigned short and a wchar_t in the library. To be most
854 consistent with previous practice, we add this explicit specialisation to ensure that a single
855 unsigned short is read and written as a character.
856
857 If you wish to read and write unsigned shorts as integers, we recommend you consider making
858 wchar_t a native type by using the /Zc:wchar_t compiler switch.
859 */
860 template <> inline
861     basic_istream<unsigned short, char_traits<unsigned short> >&__CLR_OR_THIS_CALL  
862     basic_istream<unsigned short, char_traits<unsigned short> >::operator>>(
863         unsigned short& _Ch)
864     {    // extract a character      
865     typedef basic_istream<unsigned short, char_traits<unsigned short> > _Myis;
866     typedef char_traits<unsigned short> _Traits;
867     _Myis::int_type _Meta;
868     _Myis &_Istr=*this;
869     ios_base::iostate _State = ios_base::goodbit;
870     const _Myis::sentry _Ok(_Istr);
871
872     if (_Ok)
873         {    // state okay, extract characters
874         _TRY_IO_BEGIN
875         _Meta = _Istr.rdbuf()->sbumpc();
876         if (_Traits::eq_int_type(_Traits::eof(), _Meta))
877             _State |= ios_base::eofbit | ios_base::failbit;    // end of file
878         else
879             _Ch = _Traits::to_char_type(_Meta);    // got a character
880         _CATCH_IO_(_Istr)
881         }
882
883     _Istr.setstate(_State);
884     return (_Istr);
885     }
886 #endif
887
888  #if defined(_DLL_CPPLIB) && !defined(_M_CEE_PURE)
889
890 template class _CRTIMP2_PURE basic_istream<char, char_traits<char> >;
891 template class _CRTIMP2_PURE basic_istream<wchar_t, char_traits<wchar_t> >;
892
893
894
895  #endif /* _DLL_CPPLIB */
896
897         // TEMPLATE CLASS basic_iostream
898 template<class _Elem,
899     class _Traits>
900     class basic_iostream
901     : public basic_istream<_Elem, _Traits>,
902         public basic_ostream<_Elem, _Traits>
903     {    // control insertions and extractions from a stream buffer
904 public:
905     typedef _Elem char_type;
906     typedef _Traits traits_type;
907     typedef typename _Traits::int_type int_type;
908     typedef typename _Traits::pos_type pos_type;
909     typedef typename _Traits::off_type off_type;
910
911     explicit __CLR_OR_THIS_CALL basic_iostream(basic_streambuf<_Elem, _Traits> *_Strbuf)
912         : basic_istream<_Elem, _Traits>(_Strbuf, false),
913             basic_ostream<_Elem, _Traits>(_Noinit, false)
914         {    // construct from stream buffer pointer
915         }
916
917     virtual __CLR_OR_THIS_CALL ~basic_iostream()
918         {    // destroy the object
919         }
920     };
921
922  #if defined(_DLL_CPPLIB) && !defined(_M_CEE_PURE)
923
924 template class _CRTIMP2_PURE basic_iostream<char, char_traits<char> >;
925 template class _CRTIMP2_PURE basic_iostream<wchar_t, char_traits<wchar_t> >;
926
927
928
929  #endif /* _DLL_CPPLIB */
930
931         // EXTRACTORS
932 template<class _Elem,
933     class _Traits> inline
934     basic_istream<_Elem, _Traits>& __CLRCALL_OR_CDECL operator>>(
935         basic_istream<_Elem, _Traits>& _Istr, _Elem *_Str)
936     {    // extract NTBS
937     _DEBUG_POINTER(_Str);
938     typedef basic_istream<_Elem, _Traits> _Myis;
939     typedef ctype<_Elem> _Ctype;
940     ios_base::iostate _State = ios_base::goodbit;
941     _Elem *_Str0 = _Str;
942     const typename _Myis::sentry _Ok(_Istr);
943
944     if (_Ok)
945         {    // state okay, extract characters
946         const _Ctype& _Ctype_fac = _USE(_Istr.getloc(), _Ctype);
947
948         _TRY_IO_BEGIN
949         streamsize _Count = 0 < _Istr.width() ? _Istr.width() : INT_MAX;
950         typename _Myis::int_type _Meta = _Istr.rdbuf()->sgetc();
951         _Elem _Ch;
952         for (; 0 < --_Count; _Meta = _Istr.rdbuf()->snextc())
953             if (_Traits::eq_int_type(_Traits::eof(), _Meta))
954                 {    // end of file, quit
955                 _State |= ios_base::eofbit;
956                 break;
957                 }
958             else if (_Ctype_fac.is(_Ctype::space,
959                 _Ch = _Traits::to_char_type(_Meta))
960                     || _Ch == _Elem())
961                 break;    // whitespace or nul, quit
962             else
963                 *_Str++ = _Traits::to_char_type(_Meta);    // add it to string
964         _CATCH_IO_(_Istr)
965         }
966
967     *_Str = _Elem();    // add terminating null character
968     _Istr.width(0);
969     _Istr.setstate(_Str == _Str0 ? _State | ios_base::failbit : _State);
970     return (_Istr);
971     }
972
973 template<class _Elem,
974     class _Traits> inline
975     basic_istream<_Elem, _Traits>& __CLRCALL_OR_CDECL  operator>>(
976         basic_istream<_Elem, _Traits>& _Istr, _Elem& _Ch)
977     {    // extract a character
978     typedef basic_istream<_Elem, _Traits> _Myis;
979     typename _Myis::int_type _Meta;
980     ios_base::iostate _State = ios_base::goodbit;
981     const typename _Myis::sentry _Ok(_Istr);
982
983     if (_Ok)
984         {    // state okay, extract characters
985         _TRY_IO_BEGIN
986         _Meta = _Istr.rdbuf()->sbumpc();
987         if (_Traits::eq_int_type(_Traits::eof(), _Meta))
988             _State |= ios_base::eofbit | ios_base::failbit;    // end of file
989         else
990             _Ch = _Traits::to_char_type(_Meta);    // got a character
991         _CATCH_IO_(_Istr)
992         }
993
994     _Istr.setstate(_State);
995     return (_Istr);
996     }
997
998 #ifdef _MSC_VER
999 template<class _Traits> inline
1000     basic_istream<char, _Traits>& __CLRCALL_OR_CDECL  operator>>(
1001         basic_istream<char, _Traits>& _Istr, signed char *_Str)
1002     {    // extract a signed char NTBS
1003     return (_Istr >> (char *)_Str);
1004     }
1005
1006 template<class _Traits> inline
1007     basic_istream<char, _Traits>& __CLRCALL_OR_CDECL  operator>>(
1008         basic_istream<char, _Traits>& _Istr, signed char& _Ch)
1009     {    // extract a signed char
1010     return (_Istr >> (char&)_Ch);
1011     }
1012
1013 template<class _Traits> inline
1014     basic_istream<char, _Traits>& __CLRCALL_OR_CDECL  operator>>(
1015         basic_istream<char, _Traits>& _Istr, unsigned char *_Str)
1016     {    // extract an unsigned char NTBS
1017     return (_Istr >> (char *)_Str);
1018     }
1019
1020 template<class _Traits> inline
1021     basic_istream<char, _Traits>& __CLRCALL_OR_CDECL  operator>>(
1022         basic_istream<char, _Traits>& _Istr, unsigned char& _Ch)
1023     {    // extract an unsigned char
1024     return (_Istr >> (char&)_Ch);
1025     }
1026
1027 #endif
1028
1029         // MANIPULATORS
1030 template<class _Elem,
1031     class _Traits> inline
1032     basic_istream<_Elem, _Traits>&
1033         __CLRCALL_OR_CDECL ws(basic_istream<_Elem, _Traits>& _Istr)
1034     {    // consume whitespace
1035     typedef basic_istream<_Elem, _Traits> _Myis;
1036     typedef ctype<_Elem> _Ctype;
1037
1038     if (!_Istr.eof())
1039         {    // not at eof, okay to construct sentry and skip
1040         ios_base::iostate _State = ios_base::goodbit;
1041         const typename _Myis::sentry _Ok(_Istr, true);
1042
1043         if (_Ok)
1044             {    // state okay, extract characters
1045             const _Ctype& _Ctype_fac = _USE(_Istr.getloc(), _Ctype);
1046
1047             _TRY_IO_BEGIN
1048             for (typename _Traits::int_type _Meta = _Istr.rdbuf()->sgetc(); ;
1049                 _Meta = _Istr.rdbuf()->snextc())
1050                 if (_Traits::eq_int_type(_Traits::eof(), _Meta))
1051                     {    // end of file, quit
1052                     _State |= ios_base::eofbit;
1053                     break;
1054                     }
1055                 else if (!_Ctype_fac.is(_Ctype::space,
1056                     _Traits::to_char_type(_Meta)))
1057                     break;    // not whitespace, quit
1058             _CATCH_IO_(_Istr)
1059             }
1060
1061         _Istr.setstate(_State);
1062         }
1063     return (_Istr);
1064     }
1065
1066 _CRTIMP2_PURE inline basic_istream<char, char_traits<char> >&
1067     __CLRCALL_OR_CDECL ws(basic_istream<char, char_traits<char> >& _Istr)
1068     {    // consume whitespace
1069     typedef char _Elem;
1070     typedef char_traits<_Elem> _Traits;
1071
1072     if (!_Istr.eof())
1073         {    // not at eof, okay to construct sentry and skip
1074         ios_base::iostate _State = ios_base::goodbit;
1075         const basic_istream<_Elem, _Traits>::sentry _Ok(_Istr, true);
1076
1077         if (_Ok)
1078             {    // state okay, use facet to extract
1079             const ctype<_Elem>& _Ctype_fac =
1080                 _USE(_Istr.getloc(), ctype<_Elem>);
1081
1082             _TRY_IO_BEGIN
1083             for (_Traits::int_type _Meta = _Istr.rdbuf()->sgetc(); ;
1084                 _Meta = _Istr.rdbuf()->snextc())
1085                 if (_Traits::eq_int_type(_Traits::eof(), _Meta))
1086                     {    // end of file, quit
1087                     _State |= ios_base::eofbit;
1088                     break;
1089                     }
1090                 else if (!_Ctype_fac.is(ctype<_Elem>::space,
1091                     _Traits::to_char_type(_Meta)))
1092                     break;    // not whitespace, quit
1093             _CATCH_IO_(_Istr)
1094             }
1095
1096         _Istr.setstate(_State);
1097         }
1098     return (_Istr);
1099     }
1100
1101 _CRTIMP2_PURE inline basic_istream<wchar_t, char_traits<wchar_t> >&
1102     __CLRCALL_OR_CDECL ws(basic_istream<wchar_t, char_traits<wchar_t> >& _Istr)
1103     {    // consume whitespace
1104     typedef wchar_t _Elem;
1105     typedef char_traits<_Elem> _Traits;
1106
1107     if (!_Istr.eof())
1108         {    // not at eof, okay to construct sentry and skip
1109         ios_base::iostate _State = ios_base::goodbit;
1110         const basic_istream<_Elem, _Traits>::sentry _Ok(_Istr, true);
1111
1112         if (_Ok)
1113             {    // state okay, use facet to extract
1114             const ctype<_Elem>& _Ctype_fac =
1115                 _USE(_Istr.getloc(), ctype<_Elem>);
1116
1117             _TRY_IO_BEGIN
1118             for (_Traits::int_type _Meta = _Istr.rdbuf()->sgetc(); ;
1119                 _Meta = _Istr.rdbuf()->snextc())
1120                 if (_Traits::eq_int_type(_Traits::eof(), _Meta))
1121                     {    // end of file, quit
1122                     _State |= ios_base::eofbit;
1123                     break;
1124                     }
1125                 else if (!_Ctype_fac.is(ctype<_Elem>::space,
1126                     _Traits::to_char_type(_Meta)))
1127                     break;    // not whitespace, quit
1128             _CATCH_IO_(_Istr)
1129             }
1130
1131         _Istr.setstate(_State);
1132         }
1133     return (_Istr);
1134     }
1135
1136
1137
1138  #if defined(_DLL_CPPLIB) && !defined(_M_CEE_PURE)
1139 template _CRTIMP2_PURE basic_istream<char, char_traits<char> >& __CLRCALL_OR_CDECL
1140     operator>>(basic_istream<char, char_traits<char> >&, char *);
1141 template _CRTIMP2_PURE basic_istream<char, char_traits<char> >& __CLRCALL_OR_CDECL
1142     operator>>(basic_istream<char, char_traits<char> >&, char&);
1143 template _CRTIMP2_PURE basic_istream<char, char_traits<char> >& __CLRCALL_OR_CDECL
1144     operator>>(basic_istream<char, char_traits<char> >&, signed char *);
1145 template _CRTIMP2_PURE basic_istream<char, char_traits<char> >& __CLRCALL_OR_CDECL
1146     operator>>(basic_istream<char, char_traits<char> >&, signed char&);
1147 template _CRTIMP2_PURE basic_istream<char, char_traits<char> >& __CLRCALL_OR_CDECL
1148     operator>>(basic_istream<char, char_traits<char> >&, unsigned char *);
1149 template _CRTIMP2_PURE basic_istream<char, char_traits<char> >& __CLRCALL_OR_CDECL
1150     operator>>(basic_istream<char, char_traits<char> >&, unsigned char&);
1151 template _CRTIMP2_PURE basic_istream<wchar_t, char_traits<wchar_t> >& __CLRCALL_OR_CDECL
1152     operator>>(basic_istream<wchar_t, char_traits<wchar_t> >&, wchar_t *);
1153 template _CRTIMP2_PURE basic_istream<wchar_t, char_traits<wchar_t> >& __CLRCALL_OR_CDECL
1154     operator>>(basic_istream<wchar_t, char_traits<wchar_t> >&, wchar_t&);
1155
1156
1157
1158  #endif /* _DLL_CPPLIB */
1159 _STD_END
1160
1161 #ifdef _MSC_VER
1162  #pragma warning(pop)
1163  #pragma pack(pop)
1164 #endif  /* _MSC_VER */
1165
1166 #endif /* RC_INVOKED */
1167 #endif /* _ISTREAM_ */
1168
1169 /*
1170  * Copyright (c) 1992-2006 by P.J. Plauger.  ALL RIGHTS RESERVED.
1171  * Consult your license regarding permissions and restrictions.
1172  V5.02:0009 */
1173