在系统()中有一个字符串
Having a string within a system()
如何在系统()中使用字符串。例如:(输入是字符串)
system("open -a Google Chrome" "http://www.dictionary.reference.com/browse/" + input + "?s=t");
因为当我这样做时,我收到此错误(调用"系统"没有匹配函数)。
系统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
标题?
No matching function for call to 'system'
通常发生在无法解析具有该签名的函数时。
例如:
#include <stdlib.h> // Needed for system().
int main()
{
system("some argument");
return 1;
}
并且不要忘记在将 std::string 变量作为参数传入时.c_str()
它。
看:
-
system()
文档。 - 这个答案。
相关文章:
- 如何检查一个c++字符串中有多少相同的字符/数字
- 有没有办法使用 strcpy 将字符串数组复制到另一个字符串或其他数组中?
- 有没有办法我可以在 C++ 中使用 if 语句来说明如果一个字符串不是两个名称的 eqal,它会给出一个输出,ATM i
- 我有一个返回字符串向量的函数.它需要两个字符串,并且返回一个字符串中缺少的字符串
- 对于C字符串,是否有一个标准的C++迭代器
- 我有一个字符串变量单词= "APA"
- 从 c++ 库中获取一个字符串,周围有一个 java 包装器
- C++从文件中读取不同类型的数据,直到有一个以数字开头的字符串
- 删除指向排序的字符串阵列的指针会在运行后会有一个错误
- 指针怎么能有一个字符串作为它的值
- 是否有函数/WinAPI 可以判断一个字符串是否以不区分大小写的语言方式以另一个字符串开头?
- 我有一个构造函数,但我需要将输出返回到 main.cpp.我无法使用获取字符串功能!!任何想法如何实现这一目标?
- 从C 中的线路读取(每行都有一个字符串和几个INT值)
- 在系统()中有一个字符串
- 如果我有一个字符串向量,如何使用带execvp的字符串来执行命令
- 从文件中读取数据,该文件每行都有一个字符串,其中可能有也可能没有整数
- 从文件中读取整数,中间有一个字符串
- 有一个字符串如何从第一个' /r/n/r/n '得到它的内容,直到2行从字符串结束
- 在C++中如何可能有一个字符串数组
- 有一个字符串映射如何将其与给定的字符串进行比较