public static member function
<string>

std::char_traits::eof

static int_type eof();
static constexpr int_type eof() noexcept;
End-of-File character
Returns the End-of-File value.

The End-of-File value is a special value used by many standard functions to represent an invalid character; Its value shall not compare equal to any of the values representable with char_type (as if transformed with member int_type and compared with member eq_int_type).

For the standard specializations of char_traits it returns:
specializationvalue returned by eof()
charEOF
wchar_tWEOF
char16_tA value that is not a valid UTF-16 code unit.
char32_tA value that is not a valid Unicode code point.

Parameters

none

Return Value

The End-of-File value.
Member type int_type is an integral type that can represent this value or any valid character value.

Example

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
// char_traits::eof
#include <iostream>   // std::wcin, std::wcout
#include <string>     // std::wstring, std::char_traits

int main () {
  std::wcout << "Please enter some text: ";

  if (std::wcin.peek() == std::char_traits<wchar_t>::eof()) {
    std::wcout << "Reading error";
  }
  else {
    std::wstring ws;
    std::getline (std::wcin,ws);
    std::wcout << "You entered a word: " << ws << '\n';
  }

  return 0;
}


Complexity

Constant.

Exception safety

No-throw guarantee: this member function never throws exceptions.

See also