why does copy not work?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Bruce Mac
    New Member
    • Mar 2007
    • 4

    #1

    why does copy not work?

    Hi all to all.

    first post here on the scripts

    Maybe someone could explain this to me, why is it that if i open two streams

    ifstream in ("some_doc.txt" );
    ofstream out ("copy_of_some_ doc.txt")

    to 2 txt documents and use

    string lines;
    while(getline, in) {
    in>> line;
    out<< line << endl;
    }
    in.close();
    out.close();

    i can copy line by line of some_doc to a string, then write the string to the ofstream and it will copy the txt doc exactly line by line to the new doc, copy_of_some_do c.

    now my question is, if i use the exact same code but point the istream to a jpeg, ie ("some_image.jp g") and the ofstream ("copy_of_some_ image.jpg"), why does the program not copy the image? when i drag a jpg to my txt editor, it is just a series of lines of characters, surely the streams should just copy them, or am i missing something? why do i not get a copy of the image?

    Thanks
    bruce
  • horace1
    Recognized Expert Top Contributor
    • Nov 2006
    • 1510

    #2
    if you are reading/writing non text files you should binary IO, see binary files in
    http://www.cplusplus.c om/doc/tutorial/files.html

    Comment

    • Bruce Mac
      New Member
      • Mar 2007
      • 4

      #3
      Thank you.

      sorted...

      Comment

      Working...