C++ 从stdin复制不适用于在C+中插入postgres+;使用libpqxx

C++ 从stdin复制不适用于在C+中插入postgres+;使用libpqxx,c++,postgresql,stdin,libpqxx,C++,Postgresql,Stdin,Libpqxx,我一直在尝试使用copy from stdin插入批量数据,但它不起作用。 谁能告诉我我做错了什么 // Redirecting file input to stdin std::ifstream in("infile.csv"); std::streambuf *cinbuf = std::cin.rdbuf(); // save old buffer std::cin.rdbuf(in.rdbuf()); // redirect std::cin to in std::string

我一直在尝试使用copy from stdin插入批量数据,但它不起作用。 谁能告诉我我做错了什么

// Redirecting file input to stdin
std::ifstream in("infile.csv");
std::streambuf *cinbuf = std::cin.rdbuf(); // save old buffer
std::cin.rdbuf(in.rdbuf());     // redirect std::cin to in
std::string copyQuery("COPY tableName (col1,col2) FROM STDIN DELIMITER ',' CSV HEADER");

//Database connection
std::string conninfo("host=ip port=5432 dbname=tdb user=tdbuser password=tdbpsswd);
pqxx::connection conn(conninfo);
pqxx::work transaction(conn);

pqxx::result res = transaction.exec(copyQuery);
transaction.commit();

std::cin.rdbuf(cinbuf); // reset to standard input again

我没有找到我试图插入到表中的数据

我看不出您实际上在哪里将数据传递给libpqxx。有关如何执行此操作的信息,请参阅关于表流的ligpqxx文档

最新版本的pqxx中不推荐使用表流。有替代品吗?