C++ ofstream output to image file writes different data on Windows -


im doing simple thing: writing data of image file stored string image file containing string.

std::ofstream f("image.jpeg"); f << image_data; // image_data created using python , copied over, in hex , turned ascii 

and yet, unexpected happens:

good picture

becomes:

bad picture

i cannot understand why happening.

when use python2.7 data original picture , write new file, works fine.

when compile , run program in ubuntu, picture comes out fine.

when write large text file (larger image) .txt, file comes out fine.

it jpegs on windows fails. original image tried image pgp key packet, came out half of person's head clear , other half messed up.

the compiled program doesnt mess of data, since said above, of original picture shown. also, images same size, jpeg format preserved @ least.

what happening? using ming2 4.7.2 in code::blocks on windows 7. windows being crazy?

you must open file in binary mode:

std::ofstream f("image.jpeg", std::ios::out | std::ios::binary); //                                            ^^^^^^^^^^^^^^^^ 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -