C++ 为什么我第二次尝试将JSON更改为字符串不起作用(输出窗口不会显示,即使我有breakpts或getchar)?。

C++ 为什么我第二次尝试将JSON更改为字符串不起作用(输出窗口不会显示,即使我有breakpts或getchar)?。,c++,json,visual-studio-code,nlohmann-json,C++,Json,Visual Studio Code,Nlohmann Json,在测试用例1和4中,我试图将JSON对象转换为字符串。当删除测试用例4时,代码正常工作,就像显示输出一样。但是当我包含测试用例4时,代码将无法运行。VS代码表示分段错误。我尝试对这两种代码执行j.get(),代码将被编译,但输出不会显示。有什么解决办法吗 #include "records_manager_test.hpp" #include "records_manager.hpp" #include "nlohmann/json.hpp" using js

在测试用例1和4中,我试图将JSON对象转换为字符串。当删除测试用例4时,代码正常工作,就像显示输出一样。但是当我包含测试用例4时,代码将无法运行。VS代码表示分段错误。我尝试对这两种代码执行
j.get()
,代码将被编译,但输出不会显示。有什么解决办法吗

    #include "records_manager_test.hpp"
    #include "records_manager.hpp"

    #include "nlohmann/json.hpp"

    using json = nlohmann::json;

    bool RecordsManagerTest::test1(){ //To test JSON
    json j = {
                {"1", {
                {"CategoryID",67},
                {"PatientID",90},
                {"Name","Foo"},
                {"Address","Bar"},
                {"DOB","100980"}
            }},
            {"2",{
                {"CategoryID", 6},
                {"PatientID", 9},
                {"Name", "Ryan"},
                {"Address", "161 University Ave"},
                {"DOB", "180998"}
            }}
        };
string s = j.dump(4);  //Stringfying JSON
RecordsManager test(s);
if(test.insertRecord(89,89,"Eric","161 University Avenue","010195"));
{
    test.printAsJSON();
    return true;
}
}

bool RecordsManagerTest::test2(){  // To test insert of record
RecordsManager test;
if(test.insertRecord(88,89,"Eric","161 University Avenue","040485")){
    if(test.insertRecord(88,90,"Ryan","161 University Avenue","160695")){
        return true;
    }
}
return false;
}

bool RecordsManagerTest::test3(){   //To test removal of record
RecordsManager test;
test.insertRecord(88,89,"Eric","dfdf","46465");
test.insertRecord(88,90,"Eric","dfdf","46465");
if(test.removeRecord(89,89))
    {
        test.printAsJSON();
        return true;
    }
return false;
 }

bool RecordsManagerTest::test4(){ //To test JSON
json j = {
            {"1", {
                {"CategoryID",67},
                {"PatientID",90},
                {"Name","Foo"},
                {"Address","Bar"},
                {"DOB","100980"}
            }},
            {"2",{
                {"CategoryID", 6},
                {"PatientID", 9},
                {"Name", "Ryan"},
                {"Address", "161 University Ave"},
                {"DOB", "180998"}
            }}
        };
//Stringfying JSON
string s1 = j.dump(4);
RecordsManager test(s1);
if(test.insertRecord(89,89,"Eric","161 University Avenue","010195"));
{
    test.printAsJSON();
    return true;
}
}

VS代码表示分段错误。-这意味着你的程序有一个或多个bug。如果您只有测试用例4,会发生什么?另外,哪一行出现了分割错误?分割错误出现在我的类文件中。当我只有测试用例4时,代码将运行并填充列表并打印它。我已经多次检查代码,没有错误。只有当我有测试用例1和测试用例4时,这个错误才会出现。您还没有提到是哪一行导致了这个问题。您正在使用调试器吗?是的,错误出现在我定义类的另一个文件中。奇怪的是,有时会出现这个错误,有时会编译,但输出窗口不会出现。是的,我正在使用调试器。