Created
April 17, 2026 08:33
-
-
Save m1irka/3e0e4cdc94f900379d9400a94d74440c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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