-3

Hi I have been trying to make a program that will ask for the users input and whatever the user types it will execute it as a command. Sort of like CMD

#include <iostream>
#include <string>
using namespace std;
string A;
int main(){
    for (int i = 0; i > -1; ++i){
        cout << "Command: ";
        cin >> A;

        // Here Would Be The Code

        cout << "Command Executed!";
    }
}

Here is what i imagine a possible output (if it worked)

Command: cout << "Test";
Test
Command Executed!
5
  • btw this is my first post so tell me if im doing anything wrong (or right). Commented Aug 26, 2015 at 22:26
  • You mean with CMD, a c++ code or a shell command? Commented Aug 26, 2015 at 22:27
  • @Dosisod Welcome to stackoverflow! In my opinion, your question is basically same as this one that already has been answered. Commented Aug 26, 2015 at 22:29
  • ok thanks i actually saw that right after i posted this XD. Commented Aug 26, 2015 at 22:43
  • I'd think this though if I were you. First thing I'd do with this is paste in a low-level hard disk format routine. Second thing I'd do is laugh evilly whilst hitting enter. Commented Aug 26, 2015 at 22:44

1 Answer 1

-5

You can use the system function.

http://www.cplusplus.com/reference/cstdlib/system/

system("command")
Sign up to request clarification or add additional context in comments.

2 Comments

I don't think this is what he's looking for. It looks like he wants to execute C++ function calls.
So why not ask him to clarify? Also he could create a case statement with his 'commands' and execute corresponding functions.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.