为什么从 C++ 连接到 MongoDB 会出现访问冲突?
Why is there an access violation on connecting to MongoDB from C++?
当我尝试运行这段代码时
#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{};
作为主函数中的第一行代码。
当我尝试运行这段代码时
#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{};
作为主函数中的第一行代码。