atoi函数返回值为0
使用vs2019,c++连接mysql数据库,其中表结构和数据为
查询代码为
vector<Music> Musicmanager::get_musics(string condition) {
vector<Music> muslist;
char sql[1024];
sprintf(sql, "select * from musicinfo %s", condition.c_str());
if (mysql_query(con, sql)) {
fprintf(stderr, "faild to select data : error:%s\n", mysql_error(con));
}
MYSQL_RES* res = mysql_store_result(con);
MYSQL_ROW row;
while ((row = mysql_fetch_row(res))) {
Music mus;
mus.singer = row[0];
mus.name = row[1];
mus.comp = row[2];
mus.data = std::atoi(row[4]);
muslist.push_back(mus);
}
return muslist;
}
int main(){
string str = "where singer ='rihanna'";
vector<Music> ret = Musicmanager::Getinstance()->get_musics(str);
for (auto& mus : ret)
{
cout << mus.singer << ' ' << mus.name << ' ' << mus.comp << ' ' << mus.data <<' ' << endl;
}
结果为
能解释一下为啥atoi返回值为0吗?应该怎么解决?