public static member function
<string>
static constexpr int_type eof() noexcept;
檔案結束字元
返回檔案結束值。
檔案結束值是許多標準函式使用的一個特殊值,用於表示無效字元;它的值不應與以下表示的任何值相等char_type(如果使用成員int_type轉換並與成員eq_int_type比較)。
對於char_traits的標準特化,它返回
特化 | 返回的值由eof() |
char | EOF |
wchar_t | WEOF |
char16_t | 一個不是有效UTF-16程式碼單元的值。 |
char32_t | 一個不是有效Unicode程式碼點的值。 |
返回值
檔案結束值。
成員型別int_type是一種可以表示此值或任何有效字元值的積分型別。
示例
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;
}
|