I am trying to remove the config.json file from program data, But with the below code it is showing "Permission Denied".
int main()
{
std::string f_strConfigFile = "C:\\ProgramData\\TestApplication\\TestConfig.json";
std::string l_strFileContents;
std::ifstream l_ifConfigFileStream(f_strConfigFile.c_str());
if (l_ifConfigFileStream)
{
l_ifConfigFileStream.seekg(0, ios::end);
size_t l_szFileSize = (size_t)l_ifConfigFileStream.tellg();
l_ifConfigFileStream.seekg(0, ios::beg);
char* l_chBuffer = new char[l_szFileSize + 1];
memset(l_chBuffer, 0, l_szFileSize + 1);
l_ifConfigFileStream.read(l_chBuffer, l_szFileSize + 1);
l_strFileContents.assign(l_chBuffer);
delete[] l_chBuffer;
}
l_ifConfigFileStream.close();
if (l_strFileContents.empty())
{
l_strFileContents.assign("{}");
}
if (remove(f_strConfigFile.c_str()) != 0)
{
std::cout << "Failed to remove the file" << endl;
}
else
{
std::cout << "Removed the file" << endl;
}
return 0;
}
could any one suggest how to remove the config file?