【问题标题】:C++ API unhandled exception: Microsoft C++ exception: std::bad_allocC++ API 未处理异常:Microsoft C++ 异常:std::bad_alloc
【发布时间】:2021-11-12 19:05:00
【问题描述】:

在 VS2019 (C++ API) 中,相同的代码在 Release 编译下完成,但在 DEBUG 编译下出现错误。

代码如下:

#include "include\DolphinDB.h"
#include "include\Util.h"
#include <iostream>
#include <string>

using namespace dolphindb;
using namespace std;

int main(int argc, char* argv[]) {

    string host = "192.168.2.114";
    int port = 8848;
    string username = "admin";
    string password = "123456";
    DBConnection conn;
    ConstantSP vector;
    int size=0;

    std::cout << "Connecting DolphinDB: [" << host << ":" << port << "]  Username:[" << username << "] Password:[" << password << "]" << endl;
    bool ret = conn.connect(host, port,username,password);
    if (!ret) {
        cout << "Failed to connect to the server" << endl;
        //getchar();
        //return 0;
        goto END_APP;
    }
    else
    {
        cout << "Had connected to DolphinDB server [" << host << ":" << port << "] Username=["<<username<<"]\n";
    }
    //ConstantSP vector = conn.run("`IBM`GOOG`YHOO");
    vector = conn.run("today();now()");
    size = vector->rows();
    for (int i = 0; i < size; ++i)
        cout << vector->getString(i) << endl;

END_APP: getchar();
    return 0;
}

错误如下:

未处理的异常:Microsoft C++ 异常:std::bad_alloc,位于内存 0x000000B29C97EE30。

【问题讨论】:

  • 你有没有通过调试器查看异常是在哪里抛出的?您应该能够在堆栈跟踪中看到是哪一行导致了问题

标签: c++ dolphindb


【解决方案1】:

现在使用的库是发布版本。如果项目使用debug,库也需要用debug版本编译。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-12-20
    • 2012-02-13
    • 2017-08-03
    • 2014-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-01
    相关资源
    最近更新 更多