#include <curl/curl.h>
#include <iostream>
#include <fstream>
int main(int argc, char *argv[]) {
CURL *curl;
CURLcode res;
std::ofstream file;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "https://example.com/file.txt");
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
file.open("my_file.txt", std::ios::out | std::ios::binary);
if (!file.is_open()) {
std::cerr << "Error opening file for writing." << std::endl;
return 1;
}
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &file);
res = curl_easy_perform(curl);
if(res != CURLE_OK) {
std::cerr << "curl_easy_perform() failed: " << curl_easy_strerror(res) << std::endl;
return 1;
}
curl_easy_cleanup(curl);
}
file.close();
return 0;
}