我想像这样从 abe_account 中选择 *
sqlite> select * from abe_account;
admin|Peter John|admin_account|password
但我想在 C++ 中做到这一点并返回每个元素,例如
admin as vector x[0]
Peter John as vector x[1]
admin_account as vector x[2]
password as vector x[4]
然后在我关闭 sqlite3_close(db) 时在外面使用它
例如 cout << x[0] << endl;
我该怎么做,我试图 cout << str << endl;
但它什么也没打印。
下面的代码是我自己尝试的:
#include <iostream>
#include <sqlite3.h>
//g++ -o test test.cpp -lsqlite3
using namespace std;
int main()
{
sqlite3 *db;
sqlite3_stmt * stmt;
if (sqlite3_open("abeserver.db", &db) == SQLITE_OK)
{
sqlite3_prepare( db, "SELECT * from abe_account;", -1, &stmt, NULL );//preparing the statement
sqlite3_step( stmt );//executing the statement
char * str = (char *) sqlite3_column_text( stmt, 0 );///reading the 1st column of the result
}
else
{
cout << "Failed to open db\n";
}
sqlite3_finalize(stmt);
sqlite3_close(db);
cout << str << endl;
return 0;
}