hechi 发表于 2014-4-20 08:28:16

新人求指点 官网提供的mysql++应用问题

我按照教程写了一个例子程序

int _tmain(int argc, _TCHAR* argv[])
{
mysqlpp::Connection conn(false);

if (conn.connect("MyTestdb1", "localhost", "root", "hechi14")) {
mysqlpp::Query query = conn.query("select phone from mytable");
if (mysqlpp::StoreQueryResult res = query.store()) {
cout << "We have:" << endl;
mysqlpp::StoreQueryResult::const_iterator it;

for (it = res.begin(); it != res.end(); ++it) {
mysqlpp::Row row = *it;
cout << '\t' << row << endl;
}
}
else {
cerr << "Failed to get item list: " << query.error() << endl;
return 1;
}

return 0;
}
else {
cerr << "DB connection failed: " << conn.error() << endl;
return 1;
}
return 0;
}
编译通过,但是运行的时候在在迭代器it = res.begin() 这一块总是出现读写错误,感觉是迭代器没有取到内容,但是我在mysql的command line client执行查询语句都可以的啊?我用的社区版的mysql5.6,msql++版本是3.2.1

PS: 我表中的结构是
|Name      | Sex      | Age      |Phone            |
PS又PS:
我用query.use就没问题
if (mysqlpp::UseQueryResult res = query.use())
{
cout << "We have:" << endl;
while (mysqlpp::Row row = res.fetch_row())
{
cout << row<<endl;
}
return 0;

页: [1]
查看完整版本: 新人求指点 官网提供的mysql++应用问题