以下代码不起作用:
string currency;
currency = "EURUSD";
system("lynx -dump 'http://somesite.com/q?s="+currency+"=X' > file.txt");
Run Code Online (Sandbox Code Playgroud)
我如何currency在这个C++的system()调用中使用?
这是我的错误:
Error value:
main.cpp: In function ‘int main()’:
main.cpp:22:84: error: cannot convert ‘std::basic_string<char>’ to ‘const char*’ for argument ‘1’ to ‘int system(const char*)’
make: *** [main.o] Error 1
BUILD FAILED (exit value 2, total time: 890ms)
Run Code Online (Sandbox Code Playgroud)
在PHP中我使用.连接字符串,但在C++中我不确定语法.
使用stringstream:
#include <sstream>
string currency;
currency = "EURUSD";
std::stringstream ss;
ss << "lynx -dump 'http://somesite.com/q?s=" << currency << "=X' > file.txt";
system(ss.str().c_str());
Run Code Online (Sandbox Code Playgroud)