Thread: Using variables wiht system()

  1. #1
    Registered User Bender's Avatar
    Join Date
    Jul 2004
    Posts
    3

    Using variables with system()

    Hello,
    I was just wondering how i would use a variable with the system() function i get this error every time i try:
    error C2664: 'system' : cannot convert parameter 1 from 'class String' to 'const char *'
    No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

    Thanks for your help Bender
    Last edited by Bender; 07-31-2004 at 06:53 PM.

  2. #2
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    you are tring to pass system a String, you need to use a const char*
    does your String class have a function to return the string as a const char*? the stl string class has a function called c_str() which will do this.

  3. #3
    Registered User Bender's Avatar
    Join Date
    Jul 2004
    Posts
    3
    Thanks for the response im preety sure my string library has a c_str() conversion function i found this in the my string library
    Code:
    const char * c_str( )             const;    // explicit conversion to char *
    but i dont understand the syntax for it would it be somthing like
    Code:
    String Destination="c:\\windows";
    Destination.c_str();
    system(Destination);
    Last edited by Bender; 07-31-2004 at 06:44 PM.

  4. #4
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    your close, but the c_str() function returns a c-string, that c-string is what you want to pass to system() so...
    Code:
    system(Destination.c_str());

  5. #5
    Registered User Bender's Avatar
    Join Date
    Jul 2004
    Posts
    3
    ahh thanks a lot

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 06-13-2005, 09:03 AM
  2. Replies: 3
    Last Post: 06-13-2005, 07:28 AM
  3. Why Can't C++ Be Used to Develop Operating System?
    By Antigloss in forum C++ Programming
    Replies: 7
    Last Post: 05-27-2005, 06:16 AM
  4. Putting variables in SYSTEM
    By mycro in forum C++ Programming
    Replies: 3
    Last Post: 05-29-2003, 07:59 PM
  5. System Calls && Variables
    By Okiesmokie in forum C++ Programming
    Replies: 6
    Last Post: 03-06-2002, 09:10 PM