c++可以编写代码,将用户输入作为命令执行

C++ can you make a code that executes user input as a command?

本文关键字:输入 用户 执行 命令 代码 c++      更新时间:2023-10-16

嗨,我一直在尝试制作一个程序,该程序将要求用户输入,无论用户键入什么,它都将作为命令执行。类似于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!";
    }
}

这是我想象的一个可能的输出(如果它工作)

Command: cout << "Test";
Test
Command Executed!

可以使用系统函数

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

system("command")