The char_traits, eof() member function C++ program example
Compiler: Visual C++ Express Edition 2005
Compiled on Platform: Windows XP Pro SP2
Header file: Standard
Additional library: none/default
Additional project setting: Set project to be compiled as C++
Project -> your_project_name Properties -> Configuration Properties -> C/C++ -> Advanced -> Compiled As: Compiled as C++ Code (/TP)
Other info: none
To do: Using the C++ eof(), char_traits class member to returns the end-of-file (EOF) character in C++ programming
To show: How to use eof() member function of the char_traits class to returns the end-of-file (EOF) character in C++ programming
// the char_traits class member, eof() example
#include <string>
#include <iostream>
using namespace std;
int main(void)
{
char_traits <char>::int_type int0 = char_traits<char>::eof();
cout<<"The eof return is: "<<int0<<endl;
char_traits<char>::char_type chs = 'R';
char_traits<char>::int_type int1;
int1 =char_traits<char>::to_int_type(chs);
cout<<"char_type chs "<<chs<<" = to int_type "<<int1<<endl;
char_traits <char>::int_type int2 = char_traits<char>::eof();
cout<<"The eof return is: "<<int2<<endl;
return 0;
}
Output example:
The eof return is: -1
char_type chs R = to int_type 82
The eof return is: -1
Press any key to continue . . .