I probably have a trivial question, but I canβt understand this. I wrote a simple code:
fstream file; file.open("data", ios::in); if(!file.good()){ file.close(); file.open("data", ios::out); if(!file.good()) cout<<"not good"<<endl; file<<"test"<<endl; file.close(); }
in the new VS8 C ++ Express project. When I run it and the βdataβ does not exist, it creates a file, but also returns βnot goodβ (second), so the output is not written to the file. And now comes the fun thing. If I compile the same code in VS10 C ++ Express and Code :: Blocks 12, it works fine.
Why is this so?
@edit My friend tested it on his PC using VS8 C ++ Expres. He works for him.
@ edit2 Same as my comment with "solution":
Forcing a failbit reset with .clear (); the way seems to work. It hurts when you study in the new IDE and then switch to the older one: /. Tho, this gives a good lesson. Thanks guys.
user2475983
source share