Connecting Tech Pros Worldwide Help | Site Map

printing out data from a user-defined text file

  #1  
Old September 28th, 2006, 03:55 AM
amanda.schwenk@gmail.com
Guest
 
Posts: 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?

  #2  
Old September 28th, 2006, 06:25 AM
Mike Wahler
Guest
 
Posts: n/a

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


Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Disable printing of flash in favour of internal content Neo Geshel answers 8 March 21st, 2007 05:35 PM
Disable printing of flash in favour of internal content Neo Geshel answers 8 March 21st, 2007 05:35 PM
How can I get the specific file handle information from a System.Diagnostics.Process.Start call? forest demon answers 3 November 19th, 2006 01:55 AM
string c_str() data() cout printf text file containing '\0' Tony Murphy answers 2 July 19th, 2005 09:11 PM
Printing From Python Fuzzyman answers 4 July 18th, 2005 09:01 AM