<am************@gmail.comwrote in message
news:11**********************@i42g2000cwa.googlegr oups.com...
So, I'm writing a program for my beginning C++ class and I am VERY
confused as to how to get the user defined file name opened and read
the data i need to from it.
i know i have print to the user what i want them to enter,
cin the filename
but where i get stuck is when it comes to inStream because if we don't
know the predetermined name of the file what goes in the quotes?
Don't use quotes. Use the object into which the file
name was stored via cin.
std::string name;
std::cout << "File name? ";
std::cin >name;
std::ifstream infile(name.c_str());
Admittedly, it would be nicer if the 'ifstream'
constructor took a std::string argument directly,
why this wasn't done has been the subject of
past discussions here, you can check the archives
if interested.
-Mike