Reading file path given by user

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jan 2009
Posts: 68
Reputation: gallian99 is an unknown quantity at this point 
Solved Threads: 0
gallian99 gallian99 is offline Offline
Junior Poster in Training

Reading file path given by user

 
0
  #1
Jul 30th, 2009
Hi,

I've been trying to read the file content from the file path entered by user at run time. However i always end up in error.

Help needed...

char name[100];
ifstream infile;
cout<<"Enter filename to open";
cin.getline(name,100);
infile.open(name);
if(!(infile.is_open()))
{
cout<<endl<<"File Not Found";

}

i'm not using relative path, instead the full path

You quick reply will be appreciated

thanks
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 1,968
Reputation: tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute tux4life has a reputation beyond repute 
Solved Threads: 214
tux4life's Avatar
tux4life tux4life is offline Offline
Posting Virtuoso

Re: Reading file path given by user

 
0
  #2
Jul 30th, 2009
I don't see any mistake in your code, it works fine with me.
Ensure that the file you're trying to open exists.

But...
Technically this line displays incorrect information:
cout<<endl<<"File Not Found";
It's not because the file couldn't be opened, that the file automatically doesn't exist.
For example it could be that you try to open an existing file, but this fails because of certain circumstances, then the file exists, and you display "File not found" .
Last edited by tux4life; Jul 30th, 2009 at 7:09 am.
"Never argue with idiots, they just drag you down to their level and then beat you with experience."
Reply With Quote Quick reply to this message  
Join Date: Jan 2009
Posts: 68
Reputation: gallian99 is an unknown quantity at this point 
Solved Threads: 0
gallian99 gallian99 is offline Offline
Junior Poster in Training

Re: Reading file path given by user

 
0
  #3
Jul 30th, 2009
thx, i've got sorted it out.

Originally Posted by tux4life View Post
I don't see any mistake in your code, it works fine with me.
Ensure that the file you're trying to open exists.

But...
Technically this line displays incorrect information:
cout<<endl<<"File Not Found";
It's not because the file couldn't be opened, that the file automatically doesn't exist.
For example it could be that you try to open an existing file, but this fails because of certain circumstances, then the file exists, and you display "File not found" .
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC