void FileTool::ReadFile(const char *pFileName, char *pFileContent)
{
ifstream inFile(pFileName);
string contents("");
if (inFile.is_open())
{
std::stringstream buffer;
buffer << inFile.rdbuf();
contents.append(buffer.str());
}
inFile.close();
strcpy(pFileContent, contents.c_str());
}
int FileTool::InitCom(const char *pFileName, char *pContent)
{
char *pFileContent = new char[30];
memset(pFileContent, 0, 30);
ReadFile(pFileName, pFileContent);
cJSON* root = cJSON_Parse(pFileContent);
if (root == NULL)
{
return -1111;
}
log_on_off = cJSON_GetObjectItem(root, "LOG_ON_OFF")->valueint;
char * pcContent = cJSON_GetObjectItem(root, "CommID")->valuestring;
strcpy(pContent, pcContent);
free(pcContent); pcContent = NULL;
delete []pFileContent; pFileContent = nullptr;
cJSON_Delete(root); root = nullptr;
return 0;
}
#pragma