943,931 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 16593
  • C++ RSS
Aug 31st, 2004
0

Renaming files in C++

Expand Post »
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 <fstream.h> 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?
Similar Threads
Reputation Points: 12
Solved Threads: 0
Newbie Poster
iamboredguy is offline Offline
23 posts
since Aug 2004
Aug 31st, 2004
0

Re: Renaming files in C++

Quote originally posted by iamboredguy ...
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 <fstream.h> 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
Team Colleague
Reputation Points: 2780
Solved Threads: 312
long time no c
Dave Sinkula is offline Offline
4,790 posts
since Apr 2004
Sep 1st, 2004
0

It Worked!

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.
Reputation Points: 12
Solved Threads: 0
Newbie Poster
iamboredguy is offline Offline
23 posts
since Aug 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: ODBC with Visual C++
Next Thread in C++ Forum Timeline: probelm with <fstream>; saving characters





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC