Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我是 cURL 的新手,我的作业需要它。我正在为此使用 C++。
我有这行很好用。
curl_easy_setopt(curl, CURLOPT_URL, "http://www.google.com");
但是当我将 URL 修改为变量时,就会出现我的问题。IE
string URL = "http://www.google.com"; curl_easy_setopt(curl, CURLOPT_URL, URL);
我的程序崩溃了。任何人都可以指出我的错误是什么?
CURLOPT_URL:传入一个指向要处理的实际 URL 的指针。参数应该是一个 char * 到一个以零结尾的字符串...
如果您将 URL 保存在std::string变量中,则应使用std::string::c_str().
std::string
std::string::c_str()
std::string URL = "http://www.google.com"; curl_easy_setopt(curl, CURLOPT_URL, URL.c_str());