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 begin
You can get a const char*
from an std::string
by using the c_str member function.
std::string s = ...;
const char* c = s.c_str();
If you don't want to use std::string
(maybe you don't want to do memory allocations) then you can use snprintf to create a formatted string:
#include
...
char buffer[16]; // make sure it's big enough
snprintf(buffer, sizeof(buffer), "file_%d.txt", n);
n
here is the number in the filename.