I am writing a simple program that asks the user to enter a file name then the program counts the number of files. I have gotten the body of the program to work when I hard code the file name into the code. However, when I try to use the input form the users as the file name go to. I get a complier error. I believe this is because the function wants the file name in a const char format and not a string format. Please any ideas on how to get this to work.
The preffered option is to use a c++11 compliant compiler, and specify to compile in c++11 mode. For example, using GCC or Clang you would specify -std=c++11 in the command line. IDE's probably have a build setting to let you do this. This is to provide the overloading for std::filebuf::filebuf() that allows to construct a file from a std::string.
The other option is to use std::string::c_str() to get the underlying char array, like so: