Return Value istream :: get ()

This question is about a member function basic_istream:

int_type get();

as described in N3337 27.7.2.3 # 4 (this is [istream.unformatted]). The actual standard text is supposedly the same.

The text says:

After creating a watchdog object, extracts a symbol c, if available

Returns: cif available, otherwisetraits::eof()

This text assumes that a negative charshould return a negative value. We can compare with the following section basic_istream<charT,traits>& get(char_type &c), which says:

After creating the watchdog object, extracts the symbol, if available, and assigns it c.

It is very similar to get().

, get(), ; .. basic_istream::get() C getchar(). ( EOF), . C99 getchar() , , unsigned char. basic_istream::get() .

: get() 0...UCHAR_MAX union EOF? char, int_type ( )? - ? ?

"- ", int i = cin.get() char, char ch; cin.get(ch); ?

+4
2

, . , get(). , EOF traits_type::eof(), ( char wchar_t ). , traits_type::eq_int_type(). , EOF, traits_type::to_char_type(), . , get() , traits_type::to_int_type().

, getchar() , " " EOF, , traits_type .

istream:: get():

traits_type::int_type c = in.get();
if(traits_type::not_eof(c))
    my_string += traits_type::to_char_type(c);

istream:: get():

traits_type::char_type c;
in.get(c);
if(in) // check for EOF or other input failure
    my_string += c;
+3

[ char.traits.typedefs]

typedef INT_T int_type;

: char_type INT_T , , char_-type, , eof(). int_type , iostream.

, int_type , char_type ( ), , eof(), , , char_traits<char>::int_type int, char_traits<wchar_t> wint_t.

, char , , GCC , EOF 0xff char_traits<char>::to_int_type, unsigned char int ( , , char_traits<char>::eof EOF WEOF wchar_t). 0xff EOF, GCC.

( ) get char, GCC - , .

, , (C90 6.2.1.2, C99 C11 6.3.1.3).

N, 2 ^ N, ; .

, traits_type::to_char_type ( EOF/eof(), ...).

+2

Source: https://habr.com/ru/post/1546505/


All Articles