Created
February 11, 2026 18:49
-
-
Save m1irka/d19ca250057e582b73e20a3b33db18b5 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 <string> | |
| #include <windows.h> | |
| #include <urlmon.h> | |
| #pragma comment(lib, "urlmon.lib") | |
| using namespace std; | |
| int main() { | |
| const char* cities[10] = { | |
| "odesa", "kyiv", "kharkiv", "lviv", "dnipro", | |
| "zaporizhzhia", "vinnytsia", "chernihiv", "poltava", "sumy" | |
| }; | |
| for (int i = 0; i < 10; i++) { | |
| string srcURL = "https://wttr.in/" + string(cities[i]) + "?format=%t"; | |
| const char* destFile = "weather.txt"; | |
| if (URLDownloadToFileA(0, srcURL.c_str(), destFile, 0, 0) != S_OK) { | |
| cout << cities[i] << ": Error downloading" << endl; | |
| continue; | |
| } | |
| FILE* f; | |
| fopen_s(&f, destFile, "r"); | |
| if (!f) { | |
| cout << cities[i] << ": Error opening file" << endl; | |
| continue; | |
| } | |
| char text[100]; | |
| if (fgets(text, sizeof(text), f)) { | |
| cout << cities[i] << ": " << text; | |
| } | |
| fclose(f); | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment