我期待看到一个简短的英语句子作为输出,但我看到它的十六进制值。我找不到关于这个getblob函数的任何信息,但我听说它应该用于varchar列。在我使用getString并且它崩溃应用程序之前,它很有趣但是它有时会成功打印句子后崩溃。但是我不能让它崩溃,所以我需要让它与getblob一起工作,它返回一个std :: istream,我一无所知。我尝试将istream转换为字符串,但我对isteam的缺乏了解并没有让我走得太远。
#include <iostream>
#include <sstream>
#include <memory>
#include <string>
#include <stdexcept>
#include "cppconn\driver.h"
#include "cppconn\connection.h"
#include "cppconn\statement.h"
#include "cppconn\prepared_statement.h"
#include "cppconn\resultset.h"
#include "cppconn\metadata.h"
#include "cppconn\resultset_metadata.h"
#include "cppconn\exception.h"
#include "cppconn\warning.h"
#include "cppconn\datatype.h"
#include "cppconn\parameter_metadata.h"
#include "mysql_connection.h"
#include "mysql_driver.h"
using namespace std;
int main()
{
sql::mysql::MySQL_Driver *driver;
sql::Connection *con;
sql::Statement *stmt;
// ...
driver = sql::mysql::get_mysql_driver_instance();
cout<<"Connecting to database...\n";
con = driver->connect("tcp://xx.xxx.xxx.xxx:3306", "xxxxx", "xxxxxx");
sql::ResultSet *res;
// ...
stmt = con->createStatement();
// ...
con->setSchema("mrhowtos_main");
res = stmt->executeQuery("SELECT english FROM `eng` WHERE `ID` = 16;");
while (res->next()) {
istream *stream = res->getBlob(1);
string s;
getline(*stream, s); //crashes here - access violation
cout << s << endl;
}
cout<<"done\n";
delete res;
delete stmt;
delete con;
system("PAUSE");
return 0;
}
更新:在getline上崩溃
getblob之后的流的值:
答案 0 :(得分:2)
(这回答了这个问题的第一个版本,其中有一个cout << stream << endl;
声明。)
您正在打印istream *
。
我想您想从istream
读取并打印您所阅读的内容,例如与
string s;
while (getline(*stream, s))
cout << s << endl;