I am reading the book C++ Primer and at the file input output chapter it uses:
ifstream infile(ifile.c_str());
to open a file whose name is in the string ifile
.
I tried the code and it works perfectly even without c_str()
. So what is the point of using it?
Should I use c_str()
when I am trying to open a file from a command line argument? I mean which is the correct usage:
ifstream fin( argv[1] )
or
ifstream fin( argv[1].c_str() )