Skip to content

Instantly share code, notes, and snippets.

@sunmeat
Created April 3, 2026 05:30
Show Gist options
  • Select an option

  • Save sunmeat/81124da90328b54cf56205b14fca6bd1 to your computer and use it in GitHub Desktop.

Select an option

Save sunmeat/81124da90328b54cf56205b14fca6bd1 to your computer and use it in GitHub Desktop.
get file from hosting mac os version
#include <iostream>
#include <string>
#include <curl/curl.h>
using namespace std;
size_t write_data(void* ptr, size_t size, size_t nmemb, FILE* stream) {
return fwrite(ptr, size, nmemb, stream);
}
int main()
{
string srcURL = "http://sunmeat.atwebpages.com/volley/plain.txt";
string destFile = "/tmp/file.txt"; // macOS: /tmp замість C:/1/
CURL* curl = curl_easy_init();
if (!curl) {
cerr << "Failed to init curl\n";
return 1;
}
FILE* f = fopen(destFile.c_str(), "wb");
if (!f) {
cerr << "Cannot open file for writing\n";
curl_easy_cleanup(curl);
return 1;
}
curl_easy_setopt(curl, CURLOPT_URL, srcURL.c_str());
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, f);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
CURLcode res = curl_easy_perform(curl);
fclose(f);
curl_easy_cleanup(curl);
if (res == CURLE_OK)
cout << "Saved to " << destFile << "\n";
else
cout << "Fail! " << curl_easy_strerror(res) << "\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment