Friday, June 3, 2011

(C++) How to change file names?

We learned how to have C++ open a text file, save data to it, then close the file ... but lets say I want to do that, except everytime it completes that cycle to then change the text file's name from dataset378_pending.txt -%26gt; dataset378_processed.txt ... what kind of code would I use for that?(C++) How to change file names?You could use:



(%26lt;stdio.h%26gt; or %26lt;io.h%26gt;)



rename (%26quot;dataset378_pending.txt %26quot; , %26quot;dataset378_processed.txt%26quot;);



If you are dealing with high-level type std::string (of %26lt;string%26gt;), you could do it like:



string oldName = %26quot;dataset378_pending.txt%26quot;;

string newName = %26quot;dataset378_processed.txt%26quot;;



rename (oldName.c_str (), newName.c_str ());

No comments:

Post a Comment