how to

what would be the code to ask enter a command?
and if the answer is hello then make it run another .cpp file called hello
then after it runs that command it will run the file that asked enter a command


I will be compiling this to an a.out file. if thats what its called.
plz help
something like this:

1
2
3
4
5
6
7
8
9
10
11
while(true)
{
    std::string command;
    std::cout << "enter a command: ";
    std::cin >> command;

    if(command == "hello")
        system(".\hello.exe"); // name of the programm you want to start
    if(command == "quit")
        break;
}
so what you're trying to do is you want to create a command line, kinda like terminal or Cmd.
put all the code in a while loop.(the condition should always be true, else the command wont work).
the code inside the loop should look like this:
1
2
3
4
5
6
string mycommand;
cout << "Enter A Command:";
cin >> mycommand;                  //here you type your command,for example the "hello" command
if(mycommand == "hello") {        //or any other command
system(".\hello.exe")                  //destination of the program you want to start
}
Last edited on
would it have to be a /exe? or could it be another c++ file?
would it have to be a /exe? or could it be another c++ file?

How do you run a c++ file?

do you mean open the IDE and that file in it?
Topic archived. No new replies allowed.