This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
how to declare EOF?(simple)
- From: "eric lin" <ericlin at fsshl dot zzn dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Fri, 20 May 2011 11:46:16 -0700
- Subject: how to declare EOF?(simple)
Dear g++ programers:
I just tried a piece simple c++ code, copied from c++ primer plus book(5ed, pg221), but it failed to compile, because EOF was not declared in this scope
plz help!
Eric
------------
root@eric-laptop:/home/eric/cpppp5# g++ textin4.cpp
textin4.cpp: In function ?int main()?:
textin4.cpp:9: error: ?EOF? was not declared in this scope
root@eric-laptop:/home/eric/cpppp5# cat textin4.cpp
// textin4.cpp -- reading chars with cin.get()
#include <iostream>
int main(void)
{
using namespace std;
int ch; // should be int, not char
int count = 0;
while ((ch = cin.get()) != EOF) // test for end-of-file
{
cout.put(char(ch));
++count;
}
cout << endl << count << " characters read\n";
return 0;
}