Originally Posted by
ZuK
Could you explain what an offset error should be. After all when using << and >> you're dealing with text streams. calculating offsets in a text file doesn't make much sense.
Kurt
Indeed.
C suffers from the same problem:
Code:
#include <stdio.h>
void writeInt(int);
int readInt(void);
void writeInt(int x)
{
FILE *f = fopen("int.txt", "a");
if(f)
{
fprintf(f, "%d", x);
fclose(f);
}
}
int readInt(void)
{
int x = -1;
FILE *f = fopen("int.txt", "r");
if(f)
{
fscanf(f, "%d", &x);
fclose(f);
}
return x;
}
int main(void)
{
writeInt(1);
writeInt(2);
printf("The first int written was: %d\n", readInt());
return 0;
}
Output:
Code:
The first int written was: 12
Elysia, I believe this is the kind of thing you're talking about, but I think you're putting too much demand on the standard IO functions.
How does either the standard IO functions from C or C++ know 12 is really 1 and 2 written side by side if that is your format? If you put two UINT64 variables together side by side, how does it know that you've actually done that? Given text to read and convert to a numerical value, the standard library will do what it can based upon some rules to interpret that text. There's not much more you can ask of it.
Be explicit and make sure you know what you're doing when you come up with a file format.