lundi 4 mars 2019

JSONCPP append to file

I'm using JSONCPP to log messages I get on my server, but instead of appending a message, it replaces last message. This is the code I have: the ofstream and event are private members.

  //std::ofstream myfile;
  m_file.open ("messageLogs.json");
  //Json::Value event;
  Json::Value array(Json::arrayValue);
  array.append(Json::Value(1));
  array.append(Json::Value(1));

  m_event["messages"]["time"] = "19:22";
  m_event["messages"]["message"] = msg;

  //populate object with objects
  Json::StyledWriter writer;
  m_file << writer.write(m_event) << std::endl;
  m_file.close();

Aucun commentaire:

Enregistrer un commentaire