Hello,
Please tell me in the below given code why some of the while loop condition is working and some are not! Also tell me which one is the best. Comments are already written as to which one is working and which one is not. Thanks in advance
Code:
#include"fstream.h"
int main(void)
{
ifstream f1("d:t1.txt");
char c[80],s;
clrscr();
cout<<"\n\nThe File Contains :\n";
while(f1.eof()==0) //loop works perfectly
{
f1.getline(c,80);
cout<<c;
}
while(f1) //loop for some reason doesn't work?? :(
{
f1.getline(c,80);
cout<<c;
}
while(f1.get(s)) //This condition Works for single character
{
cout<<s;
}
while(f1.getline(c,80)) //This condition doesn't Work for string!
{
cout<<c;
}
return 0;
}