#include
#include
#include "fstream"
#include "CocoStudio/Json/rapidjson/stringbuffer.h"
#include "CocoStudio/Json/rapidjson/writer.h"
//---------------------------------------------------------------------------------
void CElemDataMgr::WriteUserElem(int nUserElemId)
{
m_VecUserElem.push_back(nUserElemId);
Document Doc;
Doc.SetObject();
Value vElem;
vElem.SetArray();
int nSize = m_VecUserElem.size();
for (int i = 0; i < m_VecUserElem.size(); ++i)
{
Value vElemItem;
vElemItem.SetInt(m_VecUserElem);
vElem.PushBack(vElemItem, Doc.GetAllocator());
}
Doc.AddMember("Data", vElem, Doc.GetAllocator());
StringBuffer buffer;
Writer
Doc.Accept(writer);
std::string strJson(buffer.GetString(), buffer.Size());
CCLOG("BioEvolve::CElemDataMgr:%s", strJson.c_str());
std::string filepath = (CCFileUtils::sharedFileUtils()->getWritablePath() + "UserElem.json");
std::ofstream outfile;
outfile.open(filepath.c_str());
if (outfile.fail())
{
return;
}
outfile << strJson;
outfile.close();
}。