在system()中有一个字符串 [英] Having a string within a system()

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

问题描述

如何在system()中使用字符串.例如:(输入为字符串)

How can I use a string within a system(). ex: (input is the string)

system("open -a Google Chrome" "http://www.dictionary.reference.com/browse/" + input + "?s=t");

因为执行此操作时出现此错误(没有匹配功能可调用系统").

Because when I do this I get this error (No matching function for call to 'system').

推荐答案

系统 cstdlib 标头中可用.

函数将c样式的字符串作为参数. + 不会附加字符串文字.

Function takes a c-style string as a parameter. + doesn't append string literals.

所以尝试-

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());

这篇关于在system()中有一个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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