Thread: coppying files

  1. #1
    Ryce
    Guest

    Angry coppying files

    hey now i'm pretty sure that i got this program perfect theoreticly, but it just wont work! It says virtual memory error when i run the coppied file. If anyone could tell me whats wrong or tell me how to do it any other way i'd appreciate it:

    ifstream ifile;
    ofstream ofile;
    ifile.open("file.exe",ios::binary);
    ofile.open("copyd.exe",ios::app);
    while(!ifile.eof())
    {
    ifile.getline(storage,255);
    ofile << storage;
    }
    ifile.close();
    ofile.close();
    ---------------------------------
    got any ideas? It looks like it works but it dosnt copy correctly i guess.(??)

  2. #2
    Registered User ski6ski's Avatar
    Join Date
    Aug 2001
    Posts
    133
    I don't know much about what you are doing, but the 255 might be the problem.
    You might have to increase that number.
    C++ Is Powerful
    I use C++
    There fore I am Powerful

  3. #3
    Unregistered
    Guest
    yeah mich, you need to make it like 1000000 or somthing duh

  4. #4
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    ifstream ifile;
    ofstream ofile;
    unsigned char uc;
    // need storage. what IS storage in your example ?

    ifile.open("file.exe",ios::binary);
    ofile.open("copyd.exe",ios::binary);
    // why appending ? you want a binary copy of a file

    while(!ifile.eof())
    {
    // read a byte, write that byte
    ifile >> uc;
    ofile << uc;
    }

    ifile.close();
    ofile.close();
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  5. #5
    Registered User kitten's Avatar
    Join Date
    Aug 2001
    Posts
    109
    Ahem, copying a file byte by byte is painfully slow process. One might want to use a few KB buffer instead.
    Making error is human, but for messing things thoroughly it takes a computer

  6. #6
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    You're right... but I thought he'd like to walk before he tries to run
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    It would still seem to contain the feof() bug though.

  8. #8
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    right... try this Sorry, I don't have a compiler handy to double check...


    ifstream ifile;
    ofstream ofile;
    unsigned char uc;

    ifile.open("file.exe",ios::binary);
    ofile.open("copyd.exe",ios::binary);

    ifile >> uc;

    while(!ifile.eof())
    {
    ofile << uc;
    ifile >> uc;
    }

    ifile.close();
    ofile.close();
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  9. #9
    Ryce
    Guest

    yea

    well i tried makeing them both binary it didnt work either so thats why i left it append.

    stoarge variable is what i was going to use to store the data.
    like store the first 255 charecters place them down get the next ect.

    I tried your program i understand what your trying to do but i get a whole diffrent problem. When i ran the coppied file from my method it said out of virtual memory, when i use your method the copyed file gets an error that it preformd an illeagle operation.

    I tested a zip file withy our method, it donst seem to full copy correctly.
    Anyway whats this talk about a buffer? if that works i'd like to know. I understand the charecter by charecter i just tried to up do that with my original. I'll keep working on it!

  10. #10
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,130
    Instead of relying on running it, what about copying a textfile first
    and searching for any errors by hand ?
    This way you will see if there are any bytes ( characters ) missing
    or wrongly appended.
    If that's correct, I don't see why an executable should not
    copy correctly. However if it doesn't, use the commandline tool
    FC to compare the original and the copy:

    <in a dos window> FC /b file.exe copyd.exe
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  11. #11
    Ryce
    Guest

    Talking hey tahnk alot!

    It wasnt catching spaces(odd?) but i just used:
    ifile.get(uc);

    and it worked fine! Thanks for the help!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. add source files to embedded VC 4.0
    By George2 in forum C++ Programming
    Replies: 4
    Last Post: 06-13-2006, 03:28 AM
  2. *.cpp and *.h files understanding
    By ElastoManiac in forum C++ Programming
    Replies: 4
    Last Post: 06-11-2006, 04:45 AM
  3. Linking header files, Source files and main program(Accel. C++)
    By Daniel Primed in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2006, 11:46 AM
  4. Multiple Cpp Files
    By w4ck0z in forum C++ Programming
    Replies: 5
    Last Post: 11-14-2005, 02:41 PM
  5. header and source files
    By gtriarhos in forum C Programming
    Replies: 3
    Last Post: 10-02-2005, 03:16 AM