Thread: doing a system call

  1. #1
    Registered User
    Join Date
    May 2004
    Posts
    36

    doing a system call

    Hi guys

    In a win XP command prompt I can do the following:

    copy file1+file2 file3
    del file1
    del file2

    Is there a way that I can do this in c++?

    Cheers

  2. #2
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    Code:
    #include <cstdlib>
    ...
    system ( "del file1" );
    You can also create a C-style string and pass it into system ().

    Doing that you can get input from a user and format it all into a string and use it as an argument. That way, you can change what needs to be deleted or copied ect...
    What is C++?

  3. #3
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    minor nit: should be

    std::system ("del file1");
    hello, internet!

  4. #4
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    Quote Originally Posted by moi
    minor nit: should be

    std::system ("del file1");
    Are you sure?

    I dont think the standard "C" headers are in the std namespace.
    What is C++?

  5. #5
    Registered User jlou's Avatar
    Join Date
    Jul 2003
    Posts
    1,090
    They are supposed to be, but they aren't for some compilers (like MSVC++ 6.0).

  6. #6
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    Ah ok, that explains it. So it varies from compiler to compiler.

    I wish compilers would all just get along
    What is C++?

  7. #7
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    Quote Originally Posted by Vicious
    Are you sure?

    I dont think the standard "C" headers are in the std namespace.
    the standard c headers, ie, <stdlib.h> are outside of a namespace. the C++ "new" standard c headers, ie, <cstdlib> should be in std::
    hello, internet!

  8. #8
    Registered User
    Join Date
    May 2004
    Posts
    36
    Thanks guys. I'll give this a go.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 03-05-2009, 10:25 AM
  2. Troubleshooting Input Function
    By SiliconHobo in forum C Programming
    Replies: 14
    Last Post: 12-05-2007, 07:18 AM
  3. Inline asm
    By brietje698 in forum C++ Programming
    Replies: 5
    Last Post: 11-11-2007, 02:54 PM
  4. nanosleep() -system call does some confusing things
    By jtk in forum Linux Programming
    Replies: 5
    Last Post: 08-30-2007, 04:15 AM
  5. temperature sensors
    By danko in forum C Programming
    Replies: 22
    Last Post: 07-10-2007, 07:26 PM