尝试通过system()运行字符串命令 [英] trying to run string command through system()

查看:242
本文介绍了尝试通过system()运行字符串命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

How do I convert a string to something that I can execute via system()?

我有这个

std::string out = "some command to run" + some_string_variable;
system(out);

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

This will not compile and it's giving me a conversion error

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

No suitable conversion function from std::string to const char *

但是如果我尝试运行

system("pause");

推荐答案

尝试

system(out.c_str());

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

system function declared as below, which takes const char* as input argument:

int system(const char *command);

这篇关于尝试通过system()运行字符串命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆