hehe

解决方案 »

  1.   

    字符集是 utf8 或gb2312 或gbk 就可以支持中文了。
      

  2.   

    DROP TABLE IF EXISTS `bbs`.`codes`;
    CREATE TABLE  `bbs`.`codes` (
      `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
      `pid` int(11) DEFAULT NULL,
      `topic` mediumtext NOT NULL,
      `content` longtext NOT NULL,
      `timer` datetime NOT NULL,
      `publisher` varchar(45) NOT NULL,
      `hits` int(10) unsigned NOT NULL,
      `categoryid` varchar(45) NOT NULL,
      `classid` varchar(45) NOT NULL,
      PRIMARY KEY (`id`)
    ) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=gb2312 COMMENT='InnoDB free: 8192 kB';
    int main(int argc, char *argv[])
    {
        // Get database access parameters from command line
        const char* db = "bbs", *server = "localhost", *user = "root", *pass = "admin";
        // Connect to the sample database.
        mysqlpp::Connection conn(false);
        if (conn.connect(db, server, user, pass)) {
            // Retrieve a subset of the sample stock table set up by resetdb
            // and display it.
            mysqlpp::Query query(&conn,false,"select topic from codes");
            
            if (mysqlpp::StoreQueryResult res = query.store()) {
                cout << "We have:" << endl;
                for (size_t i = 0; i < res.num_rows(); ++i) {
                    cout << '\t' << res[i][0] << 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;
        }
    }