This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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;
}



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]