【问题标题】:C++ is executing cmd command by input possible? [duplicate]C++ 是否可以通过输入执行 cmd 命令? [复制]
【发布时间】:2020-09-02 13:04:49
【问题描述】:

我想创造这样的东西:

int main ()
{
    string s{};
    
    std::cout << "Enter CMD: \n";
    
    getline(cin,s);
    
    system(s);
}

但由于我只能在system 上使用const char,它根本不起作用,有什么不同的解决方案吗? mabye shellexecute?

【问题讨论】:

  • 它根本不工作编译器应该给你一个错误信息。

标签: c++ shell cmd system execute


【解决方案1】:

您可以使用std::string::c_str()

system(s.c_str());

【讨论】:

    猜你喜欢
    • 2021-08-01
    • 1970-01-01
    • 2017-02-16
    • 2015-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-08
    • 1970-01-01
    相关资源
    最近更新 更多