Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save XoLinA/f5654b7440bfebee1979bd27be34f12b to your computer and use it in GitHub Desktop.

Select an option

Save XoLinA/f5654b7440bfebee1979bd27be34f12b to your computer and use it in GitHub Desktop.
#include <iostream>
#include <windows.h>
#include <urlmon.h>
#include <string>
#include <ctime>
#pragma comment(lib, "urlmon.lib")
using namespace std;
int main() {
cout << "Press SPACE to download an image..." << endl;
cin.get();
string desktopPath = "C:\\Users\\Хозяин\\Desktop";
string filename = desktopPath + "\\cat_" + to_string(time(0)) + ".jpg";
const char* image_url = "https://cataas.com/cat";
HRESULT hr = URLDownloadToFileA(NULL,image_url,filename.c_str(), 0,NULL);
if (SUCCEEDED(hr))
{
cout << "Image downloaded successfully!" << endl;
cout << "Saved to: " << filename << endl;
}
else
{
cout << "Download failed!" << endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment