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+")");
}
我想在db表中存储浮点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/