Re: Saving a binary file into a string

Discussion in 'C++' started by Kaz Kylheku, Dec 28, 2009.

  1. Kaz Kylheku

    Kaz Kylheku Guest

    On 2009-12-27, Dominik Schmidt <> wrote:
    > Hi,
    >
    > I'm new to C++, so I have a very basic question.
    > I wrote a function which opens a file and saves it into a string variable.
    > Another function can save a string variable into a file.
    > I tried to combine those two functions, because in combination they should
    > make an exact copy of a file.


    Can't be done in standard C++. To make an exact copy of a file requires
    platform-specific functions. You have to retrieve all of the file's
    OS-specific attributes like ownership, permissions, modification
    timestamps, and other features like ``forks'', etc.
     
    Kaz Kylheku, Dec 28, 2009
    #1
    1. Advertising

  2. Kaz Kylheku

    Fred Zwarts Guest

    Dominik Schmidt wrote:
    > On Mon, 28 Dec 2009 04:21:00 +0000 (UTC), Kaz Kylheku wrote:
    >
    >> Can't be done in standard C++. To make an exact copy of a file
    >> requires platform-specific functions. You have to retrieve all of
    >> the file's OS-specific attributes like ownership, permissions,
    >> modification timestamps, and other features like ``forks'', etc.

    >
    > Misunderstanding.
    > I don't want to copy the file header (like ownership, permissions,
    > whatever). I only want to copy the body of the file.
    > If the hash values of my original file and its copy match, I'm happy.


    Even de separation between "body" and "meta-data" is not completely
    OS independent. E.g., on some systems the separation between
    "records" is part of the meta-data", whereas on others it is part
    of the body.
    So, even making an exact copy of the body may be OS specific.
    In practice, it may work as long as you stick to one file-type on
    one OS.
    In today's most popular OSs, Windows and Unix/Linux,
    file bodies have almost no structure at OS level. (The structure is
    determined at application level.) For those OSs a copy of the
    body is made very easily.
     
    Fred Zwarts, Dec 28, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Luis Esteban Valencia
    Replies:
    0
    Views:
    2,555
    Luis Esteban Valencia
    Jan 6, 2005
  2. G-Factor

    Saving a binary file help.

    G-Factor, Jul 7, 2003, in forum: C++
    Replies:
    7
    Views:
    450
    Thomas Matthews
    Jul 7, 2003
  3. Rune Allnor
    Replies:
    3
    Views:
    381
    Richard Herring
    Jan 15, 2010
  4. Jonathan Lee
    Replies:
    1
    Views:
    376
    Jonathan Lee
    Dec 27, 2009
  5. Jorgen Grahn
    Replies:
    4
    Views:
    449
    Kaz Kylheku
    Dec 29, 2009
Loading...

Share This Page