Created
February 7, 2026 19:40
-
-
Save ExtremeFine21/4a94792f7d34d12d12d2dda0ecd4ad10 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 <array> | |
| #include <cstdio> | |
| #include <vector> | |
| using namespace std; | |
| string runCommand(const string& cmd) { | |
| array<char, 256> buffer{}; | |
| string result; | |
| FILE* pipe = popen(cmd.c_str(), "r"); | |
| if (!pipe) return ""; | |
| while (fgets(buffer.data(), buffer.size(), pipe) != nullptr) { | |
| result += buffer.data(); | |
| } | |
| pclose(pipe); | |
| while (!result.empty() && (result.back() == '\n' || result.back() == '\r')) { | |
| result.pop_back(); | |
| } | |
| return result; | |
| } | |
| int main() { | |
| vector<string> cities = { | |
| "Odesa", | |
| "Kyiv", | |
| "Lviv", | |
| "Warsaw", | |
| "Berlin", | |
| "Paris", | |
| "London", | |
| "Rome", | |
| "Madrid", | |
| "Prague" | |
| }; | |
| cout << "Місто\tТемпература\n"; | |
| cout << "----------------------\n"; | |
| for (const string& city : cities) { | |
| string url = "https://wttr.in/" + city + "?format=%t"; | |
| string temp = runCommand("curl -s \"" + url + "\""); | |
| if (temp.empty()) { | |
| temp = "N/A"; | |
| } | |
| cout << city << "\t" << temp << endl; | |
| } | |
| return 0; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment