Download file using libcurl in C/C++
2016-07-22 15:55
507 查看
http://stackoverflow.com/questions/1636333/download-file-using-libcurl-in-c-c
#include <stdio.h> #include <curl/curl.h> /* For older cURL versions you will also need #include <curl/types.h> #include <curl/easy.h> */ #include <string> size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) { size_t written = fwrite(ptr, size, nmemb, stream); return written; } int main(void) { CURL *curl; FILE *fp; CURLcode res; char *url = "http://localhost/aaa.txt"; char outfilename[FILENAME_MAX] = "C:\\bbb.txt"; curl = curl_easy_init(); if (curl) { fp = fopen(outfilename,"wb"); curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data); curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp); res = curl_easy_perform(curl); /* always cleanup */ curl_easy_cleanup(curl); fclose(fp); } return 0; }
相关文章推荐
- 实验项目2-7:素因子分解
- C/C++中数组名退化为指针的情况
- C++文件的读写
- c++: new, delete, malloc, free的匹配使用
- 括号配对问题
- leetcode_c++:栈: Binary Tree Postorder Traversal(145)
- 实验项目2-6:数列求和
- 【C/C++】将字符串按空格逆置
- Qt/C++ Lambda 表达式
- c++ efective
- leetcode_c++:栈:Binary Tree Preorder Traversal(144)
- 【poj 2431】探险
- C语言中的函数指针与指针函数(续)
- C# 无法加载C++编译的DLL异常
- C++
- NOI1994 最佳旅游路线 解题报告
- 信号报告-week2-C语言习题集
- C语言指针函数和函数指针详细介绍
- Leetcode 102. Binary Tree Level Order Traversal (Easy) (cpp)
- 时间换算-week2-C语言习题集