Creating an output file using a variable in name

Aug 17, 2016 at 12:48am

Most tutorials use ("myfile.txt") when creating an output file.

I want to use an integer variable to automatic create a new output file for each cycle of the program.

Like (CurYear ".stats") where if CurYear = 1954 the resulting filename would be '1954.stats'.
Aug 17, 2016 at 12:59am
closed account (48T7M4Gy)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include <fstream>
#include <string>

int main () {
    std::string name = "";
    
    for(int i = 0; i < p; i++)
    {
        name = std::to_string(i) 
    }
        else std::cout << "Unable to open file";
    }
    return 0;
}
Last edited on Aug 18, 2016 at 2:37pm
Aug 17, 2016 at 4:22am
Thank you kemort
Topic archived. No new replies allowed.