A
aaragon
Hello everyone,
I'm experimenting with binary files, and it seems pretty
straightforward. It seems that I have to use the read and write member
functions, inherited by ostream. However, there is something I really
don't like about using this function and I want to know if there is a
way to avoid it.
Let's say you're writing an double to the binary file, a very simple
example:
int main() {
std:fstream fout("test.out", std:fstream::binary);
double test = 10.;
fout.write((char*)&test, sizeof(double));
fout.close();
return 0;
}
I hate to see the C cast in the write function. Is there a way to
better write this line? I really want to avoid the C way of casting.
Thank you all,
aa
I'm experimenting with binary files, and it seems pretty
straightforward. It seems that I have to use the read and write member
functions, inherited by ostream. However, there is something I really
don't like about using this function and I want to know if there is a
way to avoid it.
Let's say you're writing an double to the binary file, a very simple
example:
int main() {
std:fstream fout("test.out", std:fstream::binary);
double test = 10.;
fout.write((char*)&test, sizeof(double));
fout.close();
return 0;
}
I hate to see the C cast in the write function. Is there a way to
better write this line? I really want to avoid the C way of casting.
Thank you all,
aa