How to change input file name?

Hi there, I am new to programming, as well as to c++. I have encountered a problem while working on a programming assignment. For this particular assignment, I am asked to evaluate data from an inputfile, let it be named "infile.dat". Next, it is required to output to this same file, but with the name of this file altered to reflect the changes of data. For example, if I want to change the original file name to "changed_infile.dat.altered" by adding the "changed_" prefix and ".altered" suffix, how could this be done?

From my understanding, there are no functions in <fstream> that could change the file name. However, there is a rename function in <stdio>, but it's not exactly what I am looking for because I want to append a prefix and suffix to this existing inputfile name. Although I could apply a brute force method by simply doing rename("infile.dat", "changed_infile.dat.altered"), I want to have my program to work with various input files of different names.


I am open to any ideas and/or suggestions. Please avoid using sophisticated libraries as I am still rather nooby in the world of programming.


Thanks!


-Genxi
Thank-you for anyone who were looking into my issue. I think I have figured out how to do this.

What I did was to convert the cstring filename to a string. Next, I concatentated the prefix and suffix to this string, and converted this string back to cstring. Finally, I simply used the rename function to change the filename.


-Genxi
Topic archived. No new replies allowed.