how to declare EOF?(simple)
eric lin
ericlin@fsshl.zzn.com
Sat May 21 06:08:00 GMT 2011
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;
}
More information about the Gcc-help
mailing list