going crazy over copy

This is a discussion on going crazy over copy within the C++ Programming forums, part of the General Programming Boards category; Im going crazy over this piece of code, it compiles but the exe is huge and it doesent copy corectly, ...

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    8

    Arrow going crazy over copy

    Im going crazy over this piece of code, it compiles but the exe is huge
    and it doesent copy corectly, the file in program files is 0 kb.. (so empty)
    could annybody please tell me what to change or maybe use another
    command.. (what i basicly want to do is copy the file that is being
    executed to another directory)
    thanx !

    Code:
    const char *src = "\\instal.exe";
    ifstream input(src,ios::binary);
    
    const char *dst = "c:\\Program Files\\myprogram.exe";
    ofstream output(dst,ios::binary);
    
    output <<input.rdbuf();

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >the file in program files is 0 kb.. (so empty)
    How do you know it's empty? Did your C++ program exit before you checked the file's size?

  3. #3
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Im going crazy over this piece of code, it compiles but the exe is huge
    and it doesent copy corectly,
    Two seperate problems:
    1) The exe is huge because its being compiled with debugging symbols.
    2) Is the file name correct?
    const char *src = "\\instal.exe";
    Most install programs are spelt with 2 l's.
    Code:
    const char *src = "\\install.exe";

  4. #4
    Registered User
    Join Date
    Jul 2004
    Posts
    8
    yes the names are correct and yes the program was done
    when i checked the file size, i tested it like 20 times..
    thanx though

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Add some error checking to see if the files opened correctly.
    Code:
    const char *src = "\\instal.exe";
    ifstream input(src,ios::binary);
    if (!input.is_open())
    {
       cout << "Unable to open input file." << endl;
       return 1;
    }
    
    const char *dst = "c:\\Program Files\\myprogram.exe";
    ofstream output(dst,ios::binary);
    if (!output.is_open())
    {
       cout << "Unable to open output file." << endl;
       return 2;
    }
    
    output <<input.rdbuf();
    See if it displays either message.
    Last edited by swoopy; 07-22-2004 at 10:39 PM.

  6. #6
    Registered User
    Join Date
    Jul 2004
    Posts
    8
    doesent give anny errors but stil doesent copy right..
    thanx though..

    (dont know if i specified clearly that the file in wich this piece
    of code is, is the instal.exe so the source file that i trie to copy.
    dont know if this matters or not though)

  7. #7
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >is the instal.exe so the source file that i trie to copy.
    Well since the input file opened ok, I don't think it matters. Try closing the files.
    Code:
    output <<input.rdbuf();
    input.close();
    output.close();

  8. #8
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Try this:
    1) move the program into a temp directory.
    2) Make a fake instal.exe that has some message.
    3) instead of outputting to another file output it to the screen so you can see what you get

  9. #9
    Registered User
    Join Date
    Jul 2004
    Posts
    8
    wel gues i found one problem..

    instead of
    Code:
    const char *src = "\\instal.exe";
    i put in
    Code:
    const char *src = "instal.exe";
    now the file copy's and runs wel, but i made a "test"
    wich has like 10 lines of code, just included what i needed
    to make it run, its stil 440 ko...
    wich i think is a lil bit to much for 10 lines of code..
    now i never debuged something, i use dev c++
    tried (after compiling) to hit the debug button but it says
    Project is not compiled... maybe some last advice on
    how i debug this

    thanx ..

  10. #10
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    To remove the debugging symbols and reduce the file size
    In Dev-C++:
    Tools -> Compiler Options -> Settings -> Linker -> Generate debugging information -> No

  11. #11
    Registered User
    Join Date
    Jul 2004
    Posts
    8
    the Generate debugging information is already set on no...
    thanx though

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. calling copy constructor from template
    By Ancient Dragon in forum C++ Programming
    Replies: 3
    Last Post: 09-28-2005, 01:54 PM
  2. dynamic memory alloccation & returning objects
    By haditya in forum C++ Programming
    Replies: 8
    Last Post: 04-21-2005, 11:55 PM
  3. Copy Constructor crashing program
    By bob2509 in forum C++ Programming
    Replies: 5
    Last Post: 11-12-2002, 03:21 PM
  4. Quick ? on copy constructor
    By Traveller in forum C++ Programming
    Replies: 3
    Last Post: 05-03-2002, 10:31 AM
  5. Copy Constructor Help
    By Jubba in forum C++ Programming
    Replies: 2
    Last Post: 11-07-2001, 10:15 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21