我想在POST curl中使用动态变量 我使用这段代码:
int send(const char*s)
{
CURL *curl;
CURLcode res;
curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://localhost/query.php");
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "q=" + s);
res = curl_easy_perform(curl);
if(res != CURLE_OK)
fprintf(stderr, "curl_easy_perform() failed: %s\n",
curl_easy_strerror(res));
curl_easy_cleanup(curl);
}
curl_global_cleanup();
std::cout << std::endl << "Query sent" << std::endl;
return 0;
}
我得到了这个错误:
test.cpp:199:57: error: invalid operands of types ‘const char [3]’ and ‘const char*’ to binary ‘operator+’
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "q=" + s);
~~~~~^~~
答案 0 :(得分:2)
你必须自己连接 Sub convertSelection()
With Selection
.Value = Application.Evaluate(.Address & "/86400000")
.NumberFormat = "hh:mm:ss.000"
End With
End Sub
和"q="
,Cpp中没有运算符s
,它将chars数组与指向chars的指针连接起来。使用+
创建字符串,将"q="
指向的数据添加到此字符串,并调用s
以获取c_str()
指针作为 curl_easy_setopt 函数的参数:< / p>
const char*