#include <curl/curl.h>
void ImageDownloader(const string& image_url, const string& save_address)
{
CURL* curl;
CURLcode res;
curl = curl_easy_init();
FILE* fp = fopen(save_address.c_str(),"wb");
res = curl_easy_setopt(curl, CURLOPT_URL, image_url.c_str());
if(res != CURLE_OK)
{
curl_easy_cleanup(curl);
return;
}
res = curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);
res = curl_easy_perform(curl);
fclose(fp);
curl_easy_cleanup(curl);
}
c++ 使用libcurl下载网络图像
最新推荐文章于 2024-03-14 11:47:23 发布
本文介绍了一个使用libcurl库实现的简单C++函数,该函数可以从指定URL下载图片并保存到本地文件。通过设置CURLOPT_URL选项来指定要下载的图片URL,并通过CURLOPT_WRITEDATA和CURLOPT_WRITEFUNCTION选项来配置文件写入行为。
5032

被折叠的 条评论
为什么被折叠?



