I am trying to do something like this:
{
cout << "command: ";
cin >> m;
cout << "option: ";
cin >> o;
system(m+o);
}
so that the user can choose which command to run and an option if wanted
I am trying to do something like this:
{
cout << "command: ";
cin >> m;
cout << "option: ";
cin >> o;
system(m+o);
}
so that the user can choose which command to run and an option if wanted
The system () function expects a char *
parameter, you also are forgetting the space separation. You should do something like this:
system(std::string(m + " " + o).c_str())
Anyway I strongly recommend you not to use the system ()
function because it's a big security hole.
For more details about this I suggest you to read the following post:
You can pass only argument to system()
- a null terminated C-style string. However, that string may contain a command to any degree of complexity as long as the host system can handle that command.
Examples:
system("ls");
system("ls -alF");
system("ls -alF | some-other-program ");
Assuming m
and o
are of type std::string
in your posted code, you probably need to use:
std::string command = m + " " + o;
system(command.c_str());