Skip to content

Instantly share code, notes, and snippets.

@Marie-zaj
Created February 16, 2026 22:18
Show Gist options
  • Select an option

  • Save Marie-zaj/82f0f5230aba1ee276a9dfb0fe1b8fe0 to your computer and use it in GitHub Desktop.

Select an option

Save Marie-zaj/82f0f5230aba1ee276a9dfb0fe1b8fe0 to your computer and use it in GitHub Desktop.
DzWeatherTowns
#include <iostream>
#include <string>
#include <vector>
#include <windows.h>
#include <urlmon.h>
#include <fstream>
#include <algorithm>
#pragma comment(lib, "urlmon.lib")
using namespace std;
int main()
{
SetConsoleOutputCP(CP_UTF8);
SetConsoleCP(CP_UTF8);
vector<string> cities = {
"Odesa",
"Kyiv",
"Lviv",
"London",
"Paris",
"Berlin",
"NewYork",
"Tokyo",
"Rome",
"Madrid"
};
cout << "Weather in my favorite cities:\n\n";
for (const string& city : cities)
{
string url = "http://wttr.in/" + city + "?format=%t";
string fileName = city + ".txt";
if (URLDownloadToFileA(NULL, url.c_str(), fileName.c_str(), 0, NULL) != S_OK)
{
cout << city << " -> Error loading data\n";
continue;
}
ifstream file(fileName);
if (!file.is_open())
{
cout << city << " -> Cannot open file\n";
continue;
}
string temp;
getline(file, temp);
temp.erase(remove(temp.begin(), temp.end(), '°'), temp.end());
cout << city << ": " << temp << endl;
file.close();
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment