<分区>
Possible Duplicate:
Why failbit set when eof on read? Is there a way out?
我正在编写一个小程序,它在 Mac OS 和 Ubuntu(Unix...)上运行良好。该程序必须读取数据文件并将字节 (char
s/unsigned char
s) 和 memcpy()
分隔成 float 。这将包括采用以下四个值的过程,读取并将它们左移到 32 位 int
中,然后将 int
的内存复制到 float
。像这样:
0x43 0x66 0x1A 0x79 -> read in int32 and memcpy() into float -> val = 230.103
As I said, this works fine for Unix, but Windows seems to interpret the char
0x1A
as an end of file (EOF) error and stop reading in data. Why does Windows do such a thing and not Unix? And how could I turn it off?
I even tried error handling by looking at the ifstream
itself and check if the EOL flag has been set. Then I would clear()
the ifstream
's error flags and continue reading (using get()
) but the damn thing always returns the same EOF / 0x1A
character and does not read in the next character.
EDIT: Added some code
ifstream input (PATH, ios::in);
if (input.is_open()) {
unsigned int counter = 0;
while (input.good()) {
BYTE byte;
byte = input.get();
printf("%i, ", byte);
counter++;
}
printf("\r%i, ", counter);
input.close();
} else {
printf("Can't open file!");
}
非常感谢任何帮助。
最大