I have the following code (C++)
vector<unsigned char> bytes;
bytes.push_back('e');
bytes.push_back('P');
bytes.push_back('R');
bytes.push_back('f');
...
ofstream file(compiledFile, ios::out | ios::binary);
file.write((const char*) &binary[0], binary.size());
file.close();
but as a result is output file I have
“rPRf”
instead of bytes.
What I’m doing wrong? I need “65505266” bytes as a result.
Thank you all.
e,P,Randfare bytes. The file is 4 characters (bytes) long and it contains what you put there.The only difference between a “binary file” and a “text file” is how linebreaks are read/written on Windows (and maybe some other special characters on very old OSes). The only difference between the character
eand the number65is how the program that you’re using to read the file chooses to display it. A text editor will displayeand a hex editor will display65.