Some possible data problem...

I am having trouble with updating a file. My code is presented here:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include <fstream>
#include <windows.h>
#include <cstring>

using namespace 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.
Last edited on
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.
Topic archived. No new replies allowed.