Created
February 5, 2026 09:23
-
-
Save sunmeat/bde6453d67c94db2bd793459d4675a53 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
| // версія для macOS: https://gist.github.com/sunmeat/421a103ab1403d51a9a01d7e43827cde | |
| #include <iostream> | |
| #include <string> | |
| #include <windows.h> | |
| #pragma comment(lib, "urlmon.lib") | |
| using namespace std; | |
| int main() { | |
| // URL для завантаження | |
| cout << "Введіть назву міста: "; | |
| string city; | |
| cin >> city; | |
| string srcURL = "https://wttr.in/" + city; | |
| // файл для збереження | |
| const char* destFile = "weather.txt"; | |
| // srcURL.c_str() - перетворюємо рядок у формат C-style string | |
| // string >>> const char* | |
| // URLDownloadToFile повертає S_OK при успіху https://learn.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/platform-apis/ms775123(v=vs.85) | |
| if (URLDownloadToFileA(0, srcURL.c_str(), destFile, 0, 0) == S_OK) | |
| cout << "Збережено в " << destFile << "\n"; | |
| FILE* file; | |
| fopen_s(&file, destFile, "r+"); // відкриваємо його для читання та запису | |
| char line[200]; | |
| while (true) { // поки все не прочитаємо | |
| fgets(line, 199, file); // зчитуємо рядок | |
| AnsiToOem(line, line); // перетворюємо кодування | |
| if (feof(file) == 0) // якщо файл ще не закінчився | |
| cout << line; // показуємо рядок на екрані консолі | |
| else break; | |
| } | |
| // відкриття файлу після роботи програми | |
| ShellExecuteA(0, "open", destFile, 0, 0, SW_SHOWNORMAL); | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
круто!