试图通过system()运行字符串命令

nku*_*eck 1 c++ windows string visual-studio-2010

如何将字符串转换为可以通过system()执行的字符串?

我有这个

std::string out = "some command to run" + some_string_variable;
system(out);
Run Code Online (Sandbox Code Playgroud)

这将无法编译,它给我一个转换错误

从std :: string到const char*没有合适的转换函数

但如果我试着跑

system("pause");
Run Code Online (Sandbox Code Playgroud)

这样可行

bil*_*llz 7

尝试

system(out.c_str());
Run Code Online (Sandbox Code Playgroud)

系统函数声明如下,const char*作为输入参数:

int system(const char *command);
Run Code Online (Sandbox Code Playgroud)