Download file using libcurl in C/C++
C++ in File Using Download libcurl
2023-09-11 14:14:22 时间
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; }
相关文章
- C++问题-Qt Visual Studio Add-in
- 【C/C++学院】(4)c++开篇/类和对象/命名空间/类型增强/三目运算符/const专题/引用专题/函数增强
- 深度探索C++对象模型--------默认构造函数
- c++ in nodejs (V8)
- Google Protocol Buffer使用经验分享(一) C++动态消息与静态消息的博弈
- ios开发,app调用资源文件到C++的方法
- C语言/C++常见习题问答集锦(七十四) 之裨补阙漏
- VS中c++文件调用c 函数 ,fatal error C1853 预编译头文件来自编译器的早期版本号,或者预编译头为 C++ 而在 C 中使用它(或相反)
- Sqlachemy的警告SAWarning: The IN-predicate on "sns_object.BIZ_ID" was invoked with an empty sequence. This results in a contradiction, which nonetheless can be expensive to evaluate.
- 【华为OD机试 2023最新 】最小调整顺序次数、特异性双端队列(C++ 100%)
- 解答私信@被c++折磨头秃的花季美少女 //C++ 写一个带命令行参数的程序,可以实现将参数求和、求平均值以及排序之后输出(参数的数量不确定)。
- C++ 简单工厂
- c++ vector 初始化_C++--vector()的用法
- How to get the window id of a window using c++ program in ubuntu?
- C++之boost库报错:note: in expansion of macro BOOST_MPL_ASSERT_NOT(八十六)
- VC2015提示warning C4996: 'MBCS_Support_Deprecated_In_MFC': MBCS support in MFC is dep
- 使用Windbg排查C++程序调用IsBadReadPtr或IsBadWritePtr引发内存访问违例问题
- C++程序运行过程中发生异常闪退,很有可能是这三个原因导致的
- C++ explicit关键字学习
- C++ 变量作用域
- C++11 非静态成员的sizeof
- 机器人C++库(1)代码生成器Robcogen使用教程
- 【跟学C++】C++映射类——map/multimap类(Study17)