Creating an output file using a variable in name


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'.
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
Thank you kemort
Topic archived. No new replies allowed.