Sep 14, 2014 at 9:14am UTC
I have a bit of code which uses system() the command it gives has parameter1 which changes all the time. So I'm trying to put in a variable. My question, is this possible if so how do I do this?
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <cstdlib>
#include <iostream>
using namespace std;
int main()
{
string varPar1 = "qwerty" ;
system("start \"\" \"C:\\map1\\map2\\map3\" \"executable.exe\" \"parameter1\" \"parameter2\"" );
//tested
system("start \"\" \"C:\\map1\\map2\\map3\" \"executable.exe\" varPar1 \"parameter2\"" );
}
Last edited on Sep 14, 2014 at 9:14am UTC
Sep 14, 2014 at 9:29am UTC
First of all, using system() is highly discouraged.
Now, you need to build your string before calling system. For example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
#include <cstdlib>
#include <iostream>
#include <string>
std::string build_string(std::string param)
{
return "echo " + param + "!" ;
}
int main()
{
std::string par = "Hello" ;
std::string line = build_string(par);
std::system(line.c_str());
}
Hello!
Last edited on Sep 14, 2014 at 9:29am UTC