Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #pragma comment(lib, "Normaliz.lib" )
- #pragma comment(lib, "wldap32.lib" )
- #pragma comment(lib, "crypt32.lib" )
- #pragma comment(lib, "Ws2_32.lib")
- #define CURL_STATICLIB
- #include "curl/curl.h"
- using namespace std;
- size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) {
- size_t written = fwrite(ptr, size, nmemb, stream);
- return written;
- }
- void download(string url, string output)
- {
- cout << "GET " << url << endl;
- // setup CURL
- CURL *curl;
- CURLcode res;
- FILE *fp;
- curl = curl_easy_init();
- if (curl)
- {
- // open
- fp = fopen(output.c_str(), "wb");
- // set CURL options
- curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
- curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_data);
- curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp);
- // perform request
- res = curl_easy_perform(curl);
- // get elapsed time
- double elapsed;
- curl_easy_getinfo(curl, CURLINFO_TOTAL_TIME, &elapsed);
- cout << "Downloaded in " << elapsed << " ms" << endl;
- // CURL cleanup
- curl_easy_cleanup(curl);
- // close file
- fclose(fp);
- return;
- }
- cout << "CURL init error" << endl;
- }
- int main(void)
- {
- download(
- "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png",
- "google-logo.png"
- );
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement