String object to system()

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sudif
    New Member
    • Apr 2007
    • 1

    #1

    String object to system()

    i want to make a c++ program that do something like this
    string str;
    cin >> str;
    str="cat " + str;
    int rv=system(str);

    is there a way to do it?
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Sure that's possible. Note that the system() function takes a char* instead of
    a string; you have to convert your string, that's all.

    kind regards,

    Jos

    Comment

    • Ganon11
      Recognized Expert Specialist
      • Oct 2006
      • 3651

      #3
      In order to make the system call happy, just write

      Code:
      system(str.c_str());
      instead of

      Code:
      system(str);

      Comment

      Working...