#include <iostream>
#include <iomanip>
#include <mysql++.h>
#include <stdio.h>
#include <Windows.h>
using namespace std;
using namespace mysqlpp;
int main(){
//在取得连接之前首先设置字符编码
mysqlpp::Connection conn(false);
conn.set_option(new mysqlpp::SetCharsetNameOption("GBK"));
conn.connect("mydb","127.0.0.1","user","password",3306);
mysqlpp::Query query=conn.query();
vector<mysqlpp::Row> v;
query<<"select * from nations";
query.storein(v);
cout.setf(ios::left);
cout<<setw(10)<<"Nation"<<setw(10)<<"Notation"<<endl;
for (vector<mysqlpp::Row>::iterator it = v.begin(); it != v.end(); ++it) {
cout<<setw(10)<<it->at(0)<<setw(10)<<it->at(1)<< endl;
}
getchar();
return 0;
}
没有评论:
发表评论