小编Jam*_*Jam的帖子

使用 libpq 在表中插入浮点数

我正在使用libpq. 我收到此错误INSERT failed: ERROR: insufficient data left in message

这是我的代码库中的相应片段:

printf ("Enter write parameter_value");
scanf("%f", &parameter_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 *)&parameter_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)

c postgresql libpq

3
推荐指数
1
解决办法
837
查看次数

将字符串与变量连接并在C/C++中将其视为宏

我试图弄清楚如何编写一个宏,将一个变量的值附加到字符串.这是一个非工作代码的片段,但我正在展示它,以便我可以解释我想要做什么

#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的值.

c++ c++11

0
推荐指数
1
解决办法
104
查看次数

标签 统计

c ×1

c++ ×1

c++11 ×1

libpq ×1

postgresql ×1