| | |
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 |
Tag cloud for C++
api application array arrays based beginner binary bmp c++ c/c++ calculator char char* class classes code compile compiler console conversion convert count data delete deploy dll download dynamic dynamiccharacterarray encryption error file format forms fstream function functions game givemetehcodez graph gui homeworkhelp iamthwee ifstream input int java lib library linker list loop looping loops map math matrix memory microsoft newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings struct temperature template templates test text text-file tree url variable vector video visual visualstudio void win32 windows winsock wordfrequency wxwidgets






