open file with a variable file name

When we want to open a file using C++ instruction, 'open()'. The file name must be 'const string'?

I have tried to find the way to use a variable file name. But it has not worked while 'fopen()' in C can!

Do anyone know how to use a variable file name for 'open' in C++?
You're misinterpreting the meaning of 'const char *'. It means "a pointer to [an array of chars that may not be modified]".
1
2
3
std::string input;
std::getline(std::cin,input);
std::fstream file(input.c_str());
Hello pccX,

This method is for your convinience.
If you change the path to a file while it is open then will you ever close such a file ?
Helios and EverBeginner,

Thank for your answers.
Topic archived. No new replies allowed.