C++ <fstream> Writing a binary file from memory, file contains extra byte?-Collection of common programming errors
msdn Hi,I’m currently writing an assembler for a CPU we’ve been designing at university. It’s mostly working fine. I’ve just noticed a small error and I cannot find any reason why it would happen. My program writes the assebly binary into memory located by a pointer. I’ve debugged and it looks as it should:00 01 FF 00 02 20 00 03 04 05 03 00 06 03 00 07 03 00 08 09 0A 0B 0C 0D 0E 0F (Thats my entire 26 byte program in memory before I write to disk).
Ok note the parts in red, in memory it is correct, but when I view my outputted file it looks like this:
00 01 FF 00 02 20 00 03 04 05 03 00 06 03 00 07 03 00 08 09 0D 0A 0B 0C 0D 0E 0F (Thats the output file, a byte 0D has somehow appeared in the output).
How could this be. I’m writing to file in the following way:
fstream fp_out(“output.bin”, ios:
ut);
for(int x = 0; x < writebyte; x++) { fp_out