Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi. i am using the eof() function but seems it does'nt work. i write
fstream f("test.txt");
while (!f.eof())
cout << "1";
and in my file i wrote "sara"
but the program doesn't finish and enters in the infinite loop . why?
please help me
thanks
Posted

Quote:
but the program doesn't finish and enters in the infinite loop . why?
Because you are not reading from the file.
 
Share this answer
 
Comments
sara74 3-Jun-14 8:20am    
oh . you're right. sorry . thanks
As explained by CPallini you are not reading the file. Use below sample code for reading

C#
fstream f( "test.txt", ios::in );
    while( !inf.eof() ) {
        cout << f.get() << "\n";
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900