-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
38 lines (32 loc) · 1.02 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "PostgresDB.hpp"
#include <iostream>
#include <limits>
int main() {
try {
PostgresDB db("postgres", "postgres", "postgres", "localhost", 5432);
int id;
while (true) {
std::cout << "Enter city ID (or 0 to exit): ";
std::cin >> id;
if (id == 0) {
break;
}
if (std::cin.fail()) {
std::cin.clear();
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
std::cerr << "Invalid input. Please enter a number." << std::endl;
continue;
}
try {
std::string city = db.getCityById(id);
std::cout << "City with ID " << id << " is " << city << std::endl;
} catch (const std::exception &e) {
std::cerr << e.what() << std::endl;
}
}
} catch (const std::exception &e) {
std::cerr << e.what() << std::endl;
return 1;
}
return 0;
}