Created
February 11, 2026 20:09
-
-
Save XoLinA/3d3932721ac9edb0d6e46c2976a667be 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> | |
| #pragma comment(lib, "urlmon.lib") | |
| using namespace std; | |
| int main() { | |
| string city[10] = {"Kyiv","Lviv","Odesa","Kharkiv","Dnipro","Zaporizhzhia","Vinnytsia","Poltava","Chernihiv","Ivano-Frankivsk"}; | |
| for (int i = 0; i < 10; i++) | |
| { | |
| string srcURL = "https://wttr.in/" + city[i]; | |
| const char* destFile = "weather.txt"; | |
| if (S_OK == URLDownloadToFileA(NULL, srcURL.c_str(), destFile, 0, NULL)); | |
| FILE* f; | |
| fopen_s(&f, destFile, "r"); | |
| if (!f) { | |
| cout << "File open error\n"; | |
| return 1; | |
| } | |
| char text[500]; | |
| while (fgets(text, sizeof(text), f)) | |
| { | |
| string line = text; | |
| size_t pos = line.find("<span class=\"ef050\">"); | |
| if (pos < line.length()) { | |
| size_t start = line.find(">", pos) + 1; | |
| size_t end = line.find("<", start); | |
| string temp = line.substr(start, end - start); | |
| cout << "\nTemperature in "<<city <<" : " << temp << endl; | |
| break; | |
| } | |
| } | |
| fclose(f); | |
| } | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment