#include <iostream>
#include <fstream>
#include <windows.h>
#include <cstring>
usingnamespace std;
int main()
{
string str = "C:/Users/owner/Desktop/New Folder";
if (CreateDirectory((str + "/temp").c_str(),0))
{
if (CopyFile((str + "/some file.txt").c_str(), (str + "/temp/some file.txt").c_str(), false))
{
ofstream thefile((str + "/temp/some file.txt").c_str());
thefile << "Some stuff" << endl;
thefile.close();
if (MoveFile((str + "/temp/some file.txt").c_str(), (str + "/some file.txt").c_str()))
{
cout << "File successfully moved to temporary folder, rewritten, and moved back!"<<endl;
} //end innermost if
else
{
cout << "Something went wrong. You might want to submit what you have."<<endl;
} //end else
} //end inner if
} //end if
return 0;
} //end main
It won't let me rename the file, so I was wondering if this would have anything to do with a security problem that I can fix, and if so, how could I solve this access problem.
EDIT: I just changed if (MoveFile((str + "/temp/some file.txt").c_str(), (str + "/some file.txt").c_str())) to if (CopyFile((str + "/temp/some file.txt").c_str(), (str + "/some file.txt").c_str(),false)) Problem solved.
But, a new problem presents itself: how to remove this temporary folder. If I cannot do this, I might as well, submit my project as it is for the beta.