使用c ++连接器将输出选择为字符串

时间:2013-05-12 19:26:40

标签: c++ mysql select

我如何将带有MySQL C ++连接器的标准SELECT的while循环的所有输出放入带分隔符的字符串中以分隔输出? 我对C ++很陌生,因此还没有学到很多东西。

我目前正在使用Visual Studio 2012编写和编译我的项目。

编辑:这是我在Barmar的评论后尝试过的:

#include <vector>
vector<string> dbOutput;
while(res->next()){
dbOutput.push_back(res->getBlob("testcolumn"));
}

但是我收到错误“没有重载函数的实例”std :: vector&lt; _Ty,_Alloc&gt; :: push_back [with _Ty = std :: string,_Alloc = std :: allocator]“匹配参数列表......“。

1 个答案:

答案 0 :(得分:1)

res->getBlob("testcolumn")返回std::istream*类型的对象,但vector<string>::push_back()只接受一个字符串作为参数(根据vector<string>定义)。

您需要将stream中的数据提取到string,然后将此string推送到vector。例如:

vector<string> dbOutput;
std::istream *blob = res->getBlob("testcolumn");
std::string blobString = "";
std::string buffer;
while (!blob->eof()){
    *blob >> buffer;
    blobString += buffer;
}
dbOutput.push_back(blobString);