问题描述
我收到堆栈损坏消息,提示“运行时检查失败 #2 - 变量‘root’周围的堆栈已损坏。”使用以下代码:
#include <json/json.h>
#include <fstream>
#include <iostream>
#include <string>
int main() {
Json::Value root;
Json::Reader reader;
ifstream file("input.json");
if (!reader.parse(file,root)) {
cout << "Failed to parse configuration\n"
<< reader.getFormattedErrorMessages();
return 0;
}
file.close();
cout << root << endl;
return 0;
}
文件 input.json 包含:
[
{
"id": "id"
}
]
知道为什么会发生这种情况以及如何调试吗?
提前致谢!!
解决方法
jsoncpp 中的 Reader 类似乎过时了。请参阅 https://github.com/open-source-parsers/jsoncpp/blob/master/example/readFromStream/readFromStream.cpp
上的最新示例