// g++ testpqxx.cpp -o testpqxx `pkg-config --libs --cflags libpqxx libpq` // g++ testpqxx.cpp -o testpqxx -I /opt/PostgreSQL/9.4/include/ -L/opt/PostgreSQL/9.4/lib -lpqxx -lpq #include <iostream> #include <pqxx/pqxx> using namespace pqxx; using namespace std; int main() { try { connection conn("dbname=yout-db user=your-usr password=your-passwd \ hostaddr=127.0.0.1 port=5432"); conn.set_client_encoding("UTF8"); work w(conn); result r = w.exec("SELECT * FROM your-table"); for (result::const_iterator row = r.begin(); row != r.end(); ++row) { for (tuple::const_iterator col = row->begin(); col != row->end();++col) cout << col->c_str() << '\t'; cout << endl; } } catch (exception& e) { cerr << e.what() << endl; return 1; } return 0; }