res = PQexec(conn,"INSERT INTO worker (fullname,type) VALUES ('"ptr"',"type")");
type
是整数,ptr
是字符串。这里有什么问题?我该如何解决? “”是不是有问题
最佳答案
代替
res = PQexec(conn,"INSERT INTO worker (fullname,type) VALUES ('"ptr"',"type")");
使用字符串流创建字符串
#include <sstream>
std::stringstream ss;
ss << "INSERT INTO worker (fullname,type) VALUES ('" << ptr << "'," << type << ")";
res = PQexec(conn, ss.str().c_str() );
关于c++ - 为什么这个插入给出语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15765528/