You can get const char* from std::string using the c_str function.
std::string s = ...; const char* c = s.c_str();
If you do not want to use std::string (perhaps you do not want to do memory allocation), you can use snprintf to create a formatted string:
#include <cstdio> ... char buffer[16]; // make sure it big enough snprintf(buffer, sizeof(buffer), "file_%d.txt", n);
n here is the number in the file name.
source share