By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,389 Members | 1,878 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,389 IT Pros & Developers. It's quick & easy.

printing out data from a user-defined text file

P: n/a
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?

Sep 28 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a

<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
Sep 28 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.