Skip to content

Instantly share code, notes, and snippets.

@Marie-zaj
Created February 11, 2026 17:38
Show Gist options
  • Select an option

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

Select an option

Save Marie-zaj/ca89638ee27e58fc7911e1fb60e20df8 to your computer and use it in GitHub Desktop.
WeatherPract3
#include <iostream>
#include <string>
#include <windows.h>
#include <urlmon.h>
#pragma comment(lib, "urlmon.lib")
using namespace std;
int main() {
cout << "Enter the name of the city: ";
string city;
cin >> city;
string srcURL = "https://wttr.in/" + city;
const char* destFile = "weather.html";
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`t 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 << "The 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