How do I convert string variable to char*??

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kaushiknanda
    New Member
    • Jul 2008
    • 3

    How do I convert string variable to char*??

    hey,
    I am pretty new to c++ programming and I am supposed to use system(const char*). But I have a string variable as the argument. Can any1 please help me how to use this string variable as argument to system()? thanks in advance.
    -kaushik
  • kaushiknanda
    New Member
    • Jul 2008
    • 3

    #2
    Originally posted by kaushiknanda
    hey,
    I am pretty new to c++ programming and I am supposed to use system(const char*). But I have a string variable as the argument. Can any1 please help me how to use this string variable as argument to system()? thanks in advance.
    -kaushik

    i m getting the following error:

    cannot convert 'std::string' to 'constant char*' for argument '1' to 'int system(constant char*)'

    Comment

    • scruggsy
      New Member
      • Mar 2007
      • 147

      #3
      Originally posted by kaushiknanda
      i m getting the following error:

      cannot convert 'std::string' to 'constant char*' for argument '1' to 'int system(constant char*)'
      std::string has a c_str() function that returns a const char*, i.e.:
      Code:
      std::string stringThing("A C++ string");
      const char* cStyleString = stringThing.c_str();
      Quick google-search or peek at the index of a C++ reference book should get you acquainted with other useful std::string methods.

      Comment

      • kaushiknanda
        New Member
        • Jul 2008
        • 3

        #4
        Originally posted by scruggsy
        std::string has a c_str() function that returns a const char*, i.e.:
        Code:
        std::string stringThing("A C++ string");
        const char* cStyleString = stringThing.c_str();
        Quick google-search or peek at the index of a C++ reference book should get you acquainted with other useful std::string methods.
        thanks a lot ...it worked

        Comment

        Working...