C++ 在系统()中具有字符串
如何在system()中使用字符串。 ex:(输入是字符串) 因为当我执行此操作时,会出现此错误(没有与调用“系统”匹配的函数)。在C++ 在系统()中具有字符串,c++,string,system,C++,String,System,如何在system()中使用字符串。 ex:(输入是字符串) 因为当我执行此操作时,会出现此错误(没有与调用“系统”匹配的函数)。在cstdlib标题中可用 函数将c样式的字符串作为参数+不附加字符串文本 所以试试看- std::string cmd("open -a Google Chrome"); cmd += " http://www.dictionary.reference.com/browse/" + input + "?s=t"; // In the above case, ope
cstdlib
标题中可用
函数将c样式的字符串作为参数<代码>+不附加字符串文本
所以试试看-
std::string cmd("open -a Google Chrome");
cmd += " http://www.dictionary.reference.com/browse/" + input + "?s=t";
// In the above case, operator + overloaded in `std::string` is called and
// does the necessary concatenation.
system(cmd.c_str());
您是否包含
stdlib
标题
调用“system”时没有匹配的函数
通常在无法解析具有该签名的函数时发生
例如:
#包括//系统()所需。
int main()
{
系统(“某些论点”);
返回1;
}
在将std::string变量作为参数传入时,不要忘记.c_str()
见:
include stdlib.h和system()接受char*,而不是std::string。您真的尝试过吗?对于
输入
,您假设的数据类型是什么?如果它是std::string
,那么他的现有代码将用于连接。@BenVoigt我试图避免在两个上添加。然而,在OP的情况下,前两个字符串文字可以组合成一个。不仅如此,他的问题使用了正确的语法使编译器将它们组合起来。
std::string cmd("open -a Google Chrome");
cmd += " http://www.dictionary.reference.com/browse/" + input + "?s=t";
// In the above case, operator + overloaded in `std::string` is called and
// does the necessary concatenation.
system(cmd.c_str());
#include <stdlib.h> // Needed for system().
int main()
{
system("some argument");
return 1;
}