c++ - Saving output using hex adds white spaces? -
i have code
int main() { ifstream fin; ofstream fout; string filename = "x64-mk10game.ini"; fin.open(filename.c_str(),ios::binary); fin>>noskipws; fout.open("modded.ini"); unsigned char x; while(fin>>x) { fout<<x; } return 0; }
the thing code file this:
[main] options
the output i'm getting
[main] options
can me that?
the problem you're reading fin
in binary mode, writing fout
in text mode.
in binary mode, no reinterpretation of end-of-line characters done. in text mode on windows, reading pair \r\n
returned character \n
, , writing character \n
causes \r\n
written output stream.
so, since fin
opened in binary, hold of characters \r
, \n
. since fout
opened in text, writing \r
produces \r
, , writing \n
produces \r\n
, duplicating carriage-return character.
the solution open fout
in binary mode well. , since you're apparently interested in binary i/o, might want use unromatted i/o functions read()
, write()
instead of >>
, <<
manipulators, intended formatted i/o.
Comments
Post a Comment