| | |
How does it happens:cannot read file?
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Feb 2009
Posts: 7
Reputation:
Solved Threads: 0
Hi,guys,
I am new to C++,and recently I practice to read a file with visual studio 9.0,but it turns out that it cannot find the very file!
I ensure that the file "Dic.dat" do exist in the same file of the project,but the program only display the message "File could not be opened".
I am new to C++,and recently I practice to read a file with visual studio 9.0,but it turns out that it cannot find the very file!
C++ Syntax (Toggle Plain Text)
#include<iostream> #include<fstream> #include<string> #include<iomanip> #include<cstdlib> #include<vector> using namespace std; //using namespace stdext; int main() { ifstream inClientFile("Dic.dat",ios::in); if(!inClientFile) { cerr<<"File could not be opened"<<endl; exit(1); } ...
I ensure that the file "Dic.dat" do exist in the same file of the project,but the program only display the message "File could not be opened".
if the file "Dic.dat" is in the same directory as your source-files, your program should work fine. Are you sure that you didn't make a typo?
C++ Syntax (Toggle Plain Text)
if(!inClientFile)
C++ Syntax (Toggle Plain Text)
if(!inClientFile.good())
Knowledge is power -- But experience is everything
•
•
•
•
I am sure the "dic.dat" is in the same directory with the source file,
moreover, I tried the expression
if(!inClientFile.good())
but it didn't seem to work.
Chris
Knowledge is power -- But experience is everything
•
•
Join Date: Feb 2009
Posts: 7
Reputation:
Solved Threads: 0
I tried that,but it didn't work,either. I also have to specify the very path of the dic.dat, it failed ,too.
![]() |
Similar Threads
- Move file pointer to read next file value (C++)
- read from file help (C++)
- write and read to file (C++)
- how to read a file from client side without browsing (ASP.NET)
- C++ How can read from file.txt & where can save this file(file.txt) to start reading (C++)
- create, write & read file to/from folder (C++)
- Read in a file and store in char array (C)
Other Threads in the C++ Forum
- Previous Thread: Dont understand the error in this code
- Next Thread: cannot connect sql server in c++
| Thread Tools | Search this Thread |
api application array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamiccharacterarray email encryption error file forms fstream function functions game generator getline graph homeworkhelper iamthwee ifstream input int integer java lib linux list loop looping loops map math matrix memory multiple newbie news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates text tree url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






