gpt4 book ai didi

mysql - 使用C++在mysql中插入变量

转载 作者:行者123 更新时间:2023-11-28 23:14:39 24 4
gpt4 key购买 nike

while(true)
{
mysql_query(conn, " select close, id from fivemin order by id DESC LIMIT 5 ");

result = mysql_store_result(conn);
num_fields = mysql_num_fields(result);
float sum = 0;
while((row=mysql_fetch_row(result)))
{
sum += atof(row[0]);
last_id = atoi(row[1]);

}
float ma;
ma=sum/5.0;
if(previous_last_id != last_id)
{
cout << "Simple moving Average: " << ma << endl;
previous_last_id = last_id;
}

mysql_query(conn,"insert into sma values("+ma+")");
}

我想将 float ma 存储在我的数据库表中,但出现错误:'const char[24]' 和 'float' 类型的无效操作数转换为二进制 'operator+'

最佳答案

"insert into sma values("+ma+")" 这在 C 中不起作用。也许使用 sprintf("insert into sma values(%f)", ma);

另外,你真的想要无限循环吗?你在哪里退出它?

关于mysql - 使用C++在mysql中插入变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44410541/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com