Created
February 6, 2026 05:35
-
-
Save m1irka/9e1f7ce6d508cb2adea9b896eb56044d 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() { | |
| cout << "Enter name city: "; | |
| string city; | |
| cin >> city; | |
| string srcURL = "https://wttr.in/" + city; | |
| const char* destFile = "weather.html"; | |
| //kharkiv | |
| if (URLDownloadToFileA(0, srcURL.c_str(), destFile, 0, 0) == S_OK) { | |
| cout << "Save to " << destFile << " "; | |
| } | |
| else { | |
| cout << "Error"; | |
| return 1; | |
| } | |
| FILE* f; | |
| fopen_s(&f, destFile, "r"); | |
| if (!f) { | |
| cout << "Error, can not open file"; | |
| return 1; | |
| } | |
| char text[2000]; | |
| while (fgets(text, sizeof(text), f)) { | |
| string line = text; | |
| size_t pos = line.find("ef0"); | |
| if (pos != string::npos) { | |
| size_t start = line.find(">", pos); | |
| if (start != string::npos) { | |
| start++; | |
| size_t end = line.find("<", start); | |
| if (end != string::npos) { | |
| string temp = line.substr(start, end - start); | |
| cout << endl << "Temperature: " << temp << " C"; | |
| break; | |
| } | |
| } | |
| } | |
| } | |
| fclose(f); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment