What does inputfile.str() mean?

closed account (Sh59216C)
From my textbook, it asks the user to input the infile name
cin >> inputfile;
infile.open(inputfile.c_str());

Why does it add c_str() after the string variable inputfile??
c_str() converts a string to a const char *. The reason it does this is because fstream is not able to work directly with string variable types (of course the value stays the same).

http://www.cplusplus.com/reference/string/string/c_str/
Topic archived. No new replies allowed.