Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将MySQL结果转换为int(C++)_Mysql_C_Int_Average - Fatal编程技术网

将MySQL结果转换为int(C++)

将MySQL结果转换为int(C++),mysql,c,int,average,Mysql,C,Int,Average,我正在使用变量行[2]从MySQL检索结果。 这个变量的数据是MySQL表中的int,但是我不能把它放入C++中的int变量,因为我得到了错误消息 average.cpp:40: error: invalid conversion from char* to int 第40行istotal+=第[2]行 我做错了什么: 谢谢请查看错误,当您获得值时,它将转换为char*,因此您必须将其转换回int #include <sstream> #include <string>

我正在使用变量行[2]从MySQL检索结果。 这个变量的数据是MySQL表中的int,但是我不能把它放入C++中的int变量,因为我得到了错误消息

average.cpp:40: error: invalid conversion from char* to int
第40行istotal+=第[2]行

我做错了什么:


谢谢

请查看错误,当您获得值时,它将转换为char*,因此您必须将其转换回int

#include <sstream>
#include <string>
using namespace std;

string input(row[2]);
stringstream SS(input);
int n;

SS >> n;

total+=n;

我想多了解一些情况会有所帮助。