我正在使用libpq. 我收到此错误INSERT failed: ERROR: insufficient data left in message。
这是我的代码库中的相应片段:
printf ("Enter write parameter_value");
scanf("%f", ¶meter_value);
char *stm = "INSERT INTO write_reg_set (parameter_value) VALUES ($1::double precision)";
int nparam = 1;
//set the values to use
const char *values[1] = {(char *)¶meter_value};
//calculate the lengths of each of the values
int lengths[1] = {sizeof(parameter_value)};
//state which parameters are binary
int binary[1] = {1};
PGresult *res = PQexecParams(conn,
stm,
nparam, //number of parameters
NULL, //ignore the Oid field …Run Code Online (Sandbox Code Playgroud) 我试图弄清楚如何编写一个宏,将一个变量的值附加到字符串.这是一个非工作代码的片段,但我正在展示它,以便我可以解释我想要做什么
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
#define DATA_RESPONCE_0 23
#define DATA_RESPONCE_1 24
#define DATA_RESPONCE_2 25
#define DATA_RESPONCE_3 26
#define my_macro(x) DATA_RESPONCE_##x
int main() {
int i = 0;
int k;
k = my_macro (i);
cout << k;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,宏被扩展为DATA_RESPONCE_i,但我希望它是DATA_RESPONCE_0,因此23应该打印为k的值.