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 3 Years Ago by mike_2000_17: Fixed formatting

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

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.