Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old September 28th, 2006, 03:55 AM
amanda.schwenk@gmail.com
Guest
 
Posts: n/a
Default printing out data from a user-defined text file

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?

  #2  
Old September 28th, 2006, 06:25 AM
Mike Wahler
Guest
 
Posts: n/a
Default Re: printing out data from a user-defined text file


<amanda.schwenk@gmail.comwrote in message
news:1159412610.680286.129560@i42g2000cwa.googlegr oups.com...
Quote:
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


 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles