Problem:
Today,when i am trying to read a file with c++ file stream, but always failed.
the function in.get() always return EOF, and the in.eof () is true.
I test some cases, find a character result in this situation.
here is the test code.
Code:
fstream in ("BitIoTestData.txt",ios::out);
if (!in) {
cout << "can't open" << endl;
}
char ch = (char)26;
//cout << ch << endl;
in.put (ch); //output 0x1a into BitIoTestData.txt file
in.close ();
//open the file,read the character.
in.open ("BitIoTestData.txt", ios::in);
if (!in) {
cout << "can't open file" << endl;
}
cout << "out:" ;
cout <<(int)in.get () << endl; //return EOF,indicate failed.
I can't find out why this kind of thing will happen.
Could you give me some help?
thanks a lot. with your help,i solve the problem.
But, i still have a question.
This kind of thing is associate with windows, but why only 0x1a can't be output to a file in my original form. Can i guess that, window use 0x1a to detect the end of file? or use 0x1a do some other things? so that, i can't read it.