I'm trying to write a program in C++, which creates some files (.txt) and writes down the result in them. The problem is that an amount of these files is not fixed at the beginning and only appears near the end of the program. I would like to name these files as "file_1.txt", "file_2.txt", ..., "file_n.txt", where n is an integer.
I can't use concatenation because the file name requires type "const char*", and I didn't find any way to convert "string" to this type. I haven't found any answer through the Internet and shall be really happy if you help me.
c_str
function? en.cppreference.com/w/cpp/string/basic_string/c_str – Subjugateconst char*
in the end doesn't mean you're stuck with it for your whole program. You should usestd::string
as much as you can, then obtain aconst char*
from it only when you really it. – Scheller