Generating file names

Hi
I have to generate a programme that runs through a loop several times, untill the user is happy, each time the loop runs a .csv file has to be created. What do i do so that the file name changes each time the loop runs?[
1
2
3
4
5
6
7
8
9
10
int ARRIVEPLACE;
    ofstream myfile1, myfile;
    myfile.open ("WorkShopSimulation_.csv");
    myfile<<"Arrival place"<<","<<"ar times"<<",,"<<"sdf"<<","<<"ert"<<endl;
    while(ARRIVEPLACE<320)
    {
        myfile << ARRIVEPLACE<<","<< ARRIVALTIMES[ARRIVEPLACE] <<",,"<<ARRIVEPLACE<<","<<FINALTIMES[ARRIVEPLACE]<<endl;
        ARRIVEPLACE+=1;
    }
    myfile.close();


A filename is a string just like any other. What constraints do you have on the generated filenames?

You might try something like

WorkShopSimulation_000.csv WorkShopSimulation_001.csv WorkShopSimulation_002.csv WorkShopSimulation_003.csv

etc.
Last edited on
I was wondreing how i could get the system to do that automatically, with out the user having to change the source code?
You'll have to program something to do that no matter what. Might as well just change the source code.

If that isn't an option, then you'll have to write a shell script to rename the files after-the-fact. What OS are you using?
c++ on vistax64
Hmm, well, the simplest way for you might be just to write another C++ program that does the following:

starts, and makes sure that either
1. there are no left-over output files from the other program, or
2. that if there is a left-over output file it gets renamed properly right away.

Use CreateProcess() (#include <windows.h>) to start the other program and get its PID.

Loop:
- Check to see if the file reappears. If it does, rename it.
- You might want to look through this thread:
http://www.daniweb.com/forums/thread125002.html
- Check to see if the program has terminated. If it has, you are done.

On Windows, you can use WaitForMultipleObjectsEx() to wait for both file changes and program termination, and respond appropriately depending on which event occurred.

Good luck.
Thanks for the help
Cheers
Topic archived. No new replies allowed.