problem reading file

hi, I have this code and it reads the file, but it keeps printing the last character of the file forever, how can I make it stop?

ifstream file;
file.open("filename.txt", ios::in);
file >> c;
while (c != EOF)
{
cout << c;
file >> c;
}
Unlike fgetc, which will give you EOF on EOF, cin will become a zombie object and not respond toyour calls. This is one downside of cin/cout. You need to check whether cin.eof() returns true, instead of checking whether it gives EOF.
hmmm i'm new in programming and didn't understand really well what you said but did this and got the same results as before u__u

ifstream file;
file.open("filename.txt", ios::in);
file >> c;
while (c != cin.eof())
{
cout << c;
file >> c;
}

NOTE: im using Visual c++ 2008 express ed (if it helps)
ok, problem solved, thanks

ifstream file;
file.open("filename.txt", ios::in);
file >> c;
while (!file.eof())
{
cout << c;
file >> c;
}
Topic archived. No new replies allowed.