【问题标题】:pass a variable into curl_easy_setopt C++将变量传递给 curl_easy_setopt C++
【发布时间】:2021-05-03 17:26:45
【问题描述】:

如何将全局变量传递给 curl_easy_setopt

int agent_num = rand() % 100000;
std::string agent_name = "https://127.0.0.1:443/agent/" + agent_num;

curl_easy_setopt(curl, CURLOPT_URL, agent_name);

我尝试了不同的东西,他们给了我一个段错误任何帮助谢谢!

【问题讨论】:

标签: c++ curl libcurl


【解决方案1】:

std::string 不会自动转换为 char *。为此使用其c_str() 方法:

curl_easy_setopt(curl, CURLOPT_URL, agent_name.c_str());

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-10
    • 1970-01-01
    • 1970-01-01
    • 2019-04-03
    • 2018-01-09
    • 1970-01-01
    相关资源
    最近更新 更多