Alex White
Alex White

Reputation: 47

system("command") string in string problem

have a problem with system("command"). I want to start .exe with some parameters but "B0 P1" cant be compiled because of use "" in command string. Any solution/tips :)?

int main() {
    system ("start C:\\PROGRA~2\\BEL\\Realterm\\realterm.exe FIRST=1 SENDSTR= "B0 P3" ");
}

Upvotes: 0

Views: 72

Answers (1)

Sandro
Sandro

Reputation: 2786

You need to escape quote characters inside your string:

int main() {
    system ("start C:\\PROGRA~2\\BEL\\Realterm\\realterm.exe FIRST=1 SENDSTR= \"B0 P3\" ");
}

In c++ 11 you can also use string literal R"(...)" if you don't want to escape characters:

int main() {
    system ( R"(start C:\PROGRA~2\BEL\Realterm\realterm.exe FIRST=1 SENDSTR= "B0 P3")" );
}

Upvotes: 3

Related Questions