| | |
Reading file path given by user
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Jan 2009
Posts: 68
Reputation:
Solved Threads: 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
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
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:
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
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."
•
•
Join Date: Jan 2009
Posts: 68
Reputation:
Solved Threads: 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".
![]() |
Similar Threads
- User file path wont work!! Help!! (C++)
- opening user specified file (C++)
- Check to see if a file path is valid (Visual Basic 4 / 5 / 6)
- complete File path in fileupload is not showing in mozilla...plzz help (ASP.NET)
- Reading from a file (C++)
- reading from file (C++)
- Selecting file path from server in form (PHP)
- Help on a reading from a file programming (Java)
- Reading a Registry Key path from a file (C++)
Other Threads in the C++ Forum
- Previous Thread: assistance with final assignment
- Next Thread: error when executing dos command
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count data database delete deploy developer dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






