如何将结果集设置为字符串指针?
问题描述:
我正在使用mysql中的结果集来检索结果。如何将结果集设置为字符串指针?
我想要得到的结果字符串数组一样
MYSQL_RES *res=mysql_store_result(mysql);
MYSQL_ROW row;
while ((row = mysql_fetch_row(result)))
{
string *result=row; //there is only one row in resultset
}
string *result=row;
它给我的错误
error: cannot convert char** to std::string* in initialization
不是如何使用string?
答
您可以实现这样的:
MYSQL_RES *res=mysql_store_result(mysql);
MYSQL_ROW row;
std::vector< std::vector<std::string> > result;
int num_fields = mysql_num_fields(result);
while ((row = mysql_fetch_row(result)))
{
std::vector<std::string> a_row;
for (int i = 0; i < num_fields; i++){
a_row.push_back(row[i]);
}
result.push_back(a_row);
}