2017-02-12 38 views
-1

当我尝试运行这小小的一段代码为什么从C++连接到MongoDB时会出现访问冲突?

#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. 

有人能帮忙吗?

回答

0

我通过添加

mongocxx::instance instance{}; 

为代码在主函数的第一行固定它。

相关问题