Librairie : libpqxx
Soit une base Map(id, x, y, nom)
#include <iostream> #include <pqxx/pqxx> int main() { pqxx::connection conn("host = xx port = xx dbname = xx user = xx password = xx"); pqxx::work work(conn); pqxx::result res = work.exec("SELECT * FROM MAP"); std::cout << "Il y a " << res.size() << " lignes..." << std::endl; int id = 0; int x = 0; int y = 0; std::string name(""); for(int i = 0; i < res.size(); ++i) { std::cout << "Ligne " << i << " : " << std::endl; pqxx::result::tuple tuple = res[i]; id = tuple[0].as<int>(); x = tuple[1].as<int>(); y = tuple[2].as<int>(); name = tuple[3].as<std::string>(); std::cout << "(" << id << ") x = " << x << " y = " << y << "[" << name << "]" << std::endl; } return 0; }
g++ -o test2 main2.cc -lpqxx