What does this function mean?

I get what getline function does; however, can someone translate to me of what indata.open(file name.c_ste)) does? I know it opens the file, but what is c_stR?

1
2
3
4
5
  cout << "please enter the location of the file you wish to input: " << endl;
getline(cin, filename);

inData.open(filename.c_str());
closed account (Dy7SLyTq)
basic_string::c_str() returns a char* representation of the string value. ie
1
2
string mystr("Hello, world!\n");
cout<< mystr.c_str() << endl;

prints a char * of Hello world. pre c++ 11, ifstream::open used to only take a char * for a filename, but people would use a string because it was easier. so thats why the code is like that
I'm sorry I clearly didn't seem to understand :) im a beginner and still have yet to learn that in class. If I'm correct, c_str , is used for quotation marks in the end?...don't think that reall is the answer :D but what if you remove what will be the outcome?
is used for quotation marks in the end?...
No ist is used to convert std::string to char*.
what if you remove what will be the outcome?
If your compiler is C++11 compliant, nothing; it will work as usual. If it is not, following error will happen: "cannot convert argument 1 from std::basic_string<char> to char* in function std::ifstream::open(char*)"
Topic archived. No new replies allowed.