0

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

Edited by mike_2000_17: Fixed formatting

2
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by shazzy99
0

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" .

0

thx, i've got sorted it out.

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" .

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.