Created
February 5, 2026 09:45
-
-
Save XoLinA/23b4981062f09808b7a5372ece131cb6 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() { | |
| cout << " Enter name city: "; | |
| string city; | |
| cin >> city; | |
| // URL для завантаження | |
| string srcURL = "https://wttr.in/" + city; | |
| // файл для збереження | |
| const char* destFile = "weather.txt"; | |
| // URLDownloadToFile повертає S_OK при успіху | |
| if (S_OK == URLDownloadToFileA(NULL, srcURL.c_str(), destFile, 0, NULL)); | |
| //cout << "Збережено в " << destFile << "\n"; | |
| 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: " << 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