I am trying to send an fstream object to a function, and I provided the name of the file as a string. Now I want to type-cast the string into a character array because fstream takes a character array. However, I am wondering whether to make it static or constant or not. Also, if I wanted to make it static, should I use static_cast<const char*> or should I just use str.c_str()?
I searched the Internet but wasn't successful finding the answer I needed.
Your assumption that
fstreamonly takes a character array is wrong. Starting from C++11, it also has a ctor that takes astd::string. So you don't need to usec_stror any cast as you can just directly usestd::string.From std::fstream:
Why don't the std::fstream classes take a std::string?