У меня есть json -файл
{
"X": "3.5",
"Y": "4.4"
}
, и мне нужно изменить значение переменной x (увеличить на 0,5)
{
"X": "4.0",
"Y": "4.4"
}
Я хотел бы прочтите файл, измените переменную и запишите файл. У меня проблемы с записью (изменением) файла.
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <json/json.h>
int main(){
std::string mConfigFileName = "./test.json";
std::ifstream configFile(mConfigFileName);
std::stringstream ss;
ss << configFile.rdbuf();
std::string configString = ss.str();
Json::Value root;
Json::Reader reader;
bool ok = reader.parse(configString, root );
double X = std::stod(root["X"].asString().c_str());
std::cout << "X = "<< X << std::endl;
X += 0.5;
// how to save changes ???
}
g++ -I/usr/include/jsoncpp/ test.cpp -ljsoncpp