0

我期待看到一个简短的英文句子作为输出,但我看到它的十六进制值 instread。我找不到有关此 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 后流的值:

  • 流 0x005f3e88 {_Chcount=26806164129143632 } std::basic_istream > *
4

1 回答 1

2

(这回答了这个问题的第一个版本,其中有一个cout << stream << endl;声明。)


您正在打印一个istream *.

我想您想从中阅读istream并打印您阅读的内容,例如

string s; 
while (getline(*stream, s))
  cout << s << endl; 
于 2013-09-04T14:56:03.803 回答