我有以下回调函数。
// This is the callback function to display the select data in the table
static int callback(void *NotUsed, int argc, char **argv, char **szColName)
{
for(int i = 0; i < argc; i++)
{
std::cout << " = " << argv[i] << std::endl;
}
std::cout << "\n";
return 0;
}
// prepare our sql statements
const char *pSQL[6];
pSQL[0] = "SELECT * FROM User";
// execute sql
for(int i = 0; i < 1; i++)
{
rc = sqlite3_exec(db, pSQL[i], callback, 0, &szErrMsg);
if(rc != SQLITE_OK)
{
std::cout << "SQL Error: " << szErrMsg << std::endl;
sqlite3_free(szErrMsg);
break;
}
}
产生以下输出
1
mark
mark@email.com
98989898
mark
mark
ADMN
U
Where are you studying
SIM
0
2
ken
ken@email.com
92222898
ken
ken
ADMN
U
Where are you studying
SIM
0
3
joseph
joseph@email.com
92333718
joseph
joseph
ADMN
U
Where are you studying
SIM
0
4
ricky
ricky@email.com
81822801
ricky
ricky
ADMN
U
Where are you studying
SIM
0
5
ck
ck@email.com
94567828
ck
ck
ADMN
U
Where are you studying
SIM
0
我需要像这样水平格式化而不是垂直格式化:
1 mark mark@email.com 98989898 mark mark ADMN U Where are you studying SIM 0
2 ken ken@email.com 92222898 ken ken ADMN U Where are you studying SIM 0
3 joseph joseph@email.com 92333718 joseph joseph ADMN U Where are you studying SIM 0
4 ricky ricky@email.com 81822801 ricky ricky ADMN U Where are you studying SIM 0
5 ck ck@email.com 94567828 ck ck ADMN U Where are you studying SIM 0
我尝试在回调函数中使用它:
1) std::cout << argv[i] << "\t";
2) std::cout << argv[i] << setw(15);
3) std::cout << setw(15) << argv[i];
但它给我的只是格式错误的行。
1 mark test@email.com 98989898 mark mark ADMN U Where are you studying SIM 0
2 ken ken@email.com 92222898 ken ken ADMN U Where are you studying SIM 0
3 joseph joseph@email.com 92333718 joseph joseph ADMN U Where are you studying SIM 0
4 ricky ricky@email.com 81822801 ricky ricky ADMN U Where are you studying SIM 0
5 ck ck@email.com 94567828 ck ck ADMN U Where are you studying SIM 0