为什么从 C++ 连接到 MongoDB 时会出现访问冲突? [英] Why is there an access violation on connecting to MongoDB from C++?

查看:42
本文介绍了为什么从 C++ 连接到 MongoDB 时会出现访问冲突?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试运行这段代码时

When I try to run this little piece of code

#include <iostream>
#include <bsoncxx/builder/stream/document.hpp>
#include <bsoncxx/json.hpp>
#include <mongocxx/client.hpp>
#include <mongocxx/instance.hpp>

int main(int argc, char **argv)
{
    mongocxx::client client{mongocxx::uri{}};
    mongocxx::database db = client["xyz"];
    std::cout << "Connected to xyz." << std::endl;
}

我总是收到这个警告

Exception thrown at 0x00007FFF7815F1FD (libmongoc-1.0.dll) in Test.exe: 0xC0000005: Access violation writing location 0x0000000000000020.

有人可以帮忙吗?

推荐答案

我通过添加修复了它

mongocxx::instance instance{};

作为主函数中的第一行代码.

as the first line of code in the main function.

这篇关于为什么从 C++ 连接到 MongoDB 时会出现访问冲突?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆