I'm trying to make a program that will execute an entered command. I've tried:
const char* command = "echo Hello, World!";
system(command);
And this works fine. But I'd like to do so that the user has to type the command. And here's the problem. I've tried so:
const char* command;
cin >> command;
system(command.c_str());
And this also works fine, but only for a one-word command like cls
. But if I try to enter a command like color a
, the program saves my input data as two separate commands and executes color
and next it tries to execute a
and obviously the output is: 'a' is not recognized as an internal or external command, operable program or batch file.
So how to save the input data as a single string, which contains spaces?