954,483 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Renaming files in C++

I'm trying to use sequential binary file editing in C++. I use a temporary file. I have to make the changes in the file by storing the modified data in the temp file. Then I delete the original file and rename the temp as the original. The problem is the remove() and rename() functions in don't seem to be working. When I check in the folder after execution, the temp file is still there and so is the original file. Does any1 know an alternative method to remove and rename a file during runtime?

iamboredguy
Newbie Poster
23 posts since Aug 2004
Reputation Points: 12
Solved Threads: 0
 
I'm trying to use sequential binary file editing in C++. I use a temporary file. I have to make the changes in the file by storing the modified data in the temp file. Then I delete the original file and rename the temp as the original. The problem is the remove() and rename() functions in don't seem to be working. When I check in the folder after execution, the temp file is still there and so is the original file. Does any1 know an alternative method to remove and rename a file during runtime?

Do you have a code sample that demonstrates the problem? Are you checking return values? http://www.cplusplus.com/ref/cstdio/rename.html
http://www.cplusplus.com/ref/cstdio/remove.html

Dave Sinkula
long time no c
Team Colleague
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
 

I didn't know I had to close all variables connected to the file to be deleted. It worked after I did that. Thanks a ton Dave. :)

iamboredguy
Newbie Poster
23 posts since Aug 2004
Reputation Points: 12
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You