Hello everyone!
I (not the biggest c++ professional) spent some hours today trying to solve this problem:
I need to create a binary file and want to be able to write integers/doubles etc. directly into it. Since i am not very good at c++ i don't know what to do best.
The file begins with a 256 Bytes long header that i need to fill up.
0-7th Byte will be filled with zeros.
8-55th Byte should contain 6 doubles
...
61-191th Byte should contain 16 doubles.
etc.
First of all, i don't really know how to write a binary from stream.
I used
stream.open("path/test.txt", ios::binary)
to later write in a binary format.
Now how do I put the contents of double variables into the file so that exactly 4 Bytes will be reserved and filled with the variable's content?
I tried to check what i did by opening the file in a hex-viewer. What I did so far did not show the results i was looking for:
In the hex-viewer the file should begin with
00 00 00 00 00 00 00 00 (0-7th Byte: Zeroes).
When i wrote into the empty binary file in this way though, i got other hex numbers than zeroes in the beginning.
1 2 3 4 5 6
|
ofstream stream;
stream.open("path", ios::binary);
double k = 0;
stream << k;
stream.close();
|
I am sorry I do not know how to put the problem best. Another way of asking for your help would be: How do I write a binary File that looks like this picture (
http://www.avl-web.de/Geoheader.png) after opening it with a hex-viewer?
Many thanks for any help!