I used EOF in a C++ program to terminate a loop.. but it is not working.... could someone help me and tell me what im doing wrong.. the code for my program is..:
Code:
#include <iostream.h>
#include <fstream.h>
#include <io.h>
int main(int argc, char * argv[])
{
if(argc!=2)
{
cout<<"Correct input is: filename";
return 0;
}
if(access(argv[1], 00))
{
cout<<"File does not exist";
return 0;
}
ifstream the_file;
the_file.open(argv[1]);
int x = 0;
char placeInFile;
the_file.get(placeInFile);
while(placeInFile!=EOF)
{
if (placeInFile=='\n')
x++;
the_file.get(placeInFile);
}
cout<<"That file has "<<x<<" lines."<<endl;
return 0;
}