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

Recommended Answers

All 2 Replies

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.