0

Hello I don't success to append "myText" at end end of the photo file.

ofstream photo;
photo.open("photo.jpg",ios::app);
photo << endl << "textAdded";

It doesn't works... It does not append "textAdded" at the end of the binary file...

7
  • 4
    how do you know it does not append it? Commented Jan 26, 2016 at 14:05
  • 1
    Why do you want to append text to an image file? What do you have in mind here?
    – Galik
    Commented Jan 26, 2016 at 14:08
  • Because the I see it with sublime text
    – John Mary
    Commented Jan 26, 2016 at 14:08
  • This does not put the text in the image data, it puts the text after the image data and likely renders the image file unusable.
    – Galik
    Commented Jan 26, 2016 at 14:10
  • the code works. the file cant be opened with an image viewer anymore though Commented Jan 26, 2016 at 14:12

1 Answer 1

0

Try adding photo.close(); on a new line after what you have written

2
  • Technically this should happen automatically when the stream is destroyed, but the close() method should be called and does write pending data to the file before closing. Probably also worth adding error checking for file open errors.
    – Tom
    Commented Jan 26, 2016 at 14:16
  • This won't make any difference, the file closes automatically.
    – Galik
    Commented Jan 26, 2016 at 14:19

Not the answer you're looking for? Browse other questions tagged or ask your own question.