Skip to content

Instantly share code, notes, and snippets.

@m1irka
Created April 17, 2026 08:33
Show Gist options
  • Select an option

  • Save m1irka/3e0e4cdc94f900379d9400a94d74440c to your computer and use it in GitHub Desktop.

Select an option

Save m1irka/3e0e4cdc94f900379d9400a94d74440c to your computer and use it in GitHub Desktop.
#include <iostream>
#include <conio.h>
#include <windows.h>
#include <urlmon.h>
#include <string>
#include <ctime>
#pragma comment(lib, "urlmon.lib")
using namespace std;
int main() {
SetConsoleOutputCP(65001);
srand((unsigned)time(nullptr));
string folder = "D:\test dz";
cout << "Press SPACE to download a cat image, ESC to exit.\n";
while (true) {
int key = _getch();
if (key == 27) break;
if (key == 32) {
string url = "https://cataas.com/cat";
string dest = "D:/test dz/" + to_string(rand()) + ".jpg";
URLDownloadToFileA(nullptr, url.c_str(), dest.c_str(), 0, nullptr);
HRESULT hr = URLDownloadToFileA(nullptr, url.c_str(), dest.c_str(), 0, nullptr);
if (hr == S_OK) {
cout << "Image downloaded to: " << dest << "\n";
}
else {
cout << "Download failed, HRESULT=" << hr << "\n";
}
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment