?
Solved

Tres tres important. SIMPLE I/O questions. I feel like a noob.

Posted on 2003-03-23
5
Medium Priority
?
228 Views
Last Modified: 2010-04-01
God this sounds like a noob question, but I created this program in metroworks, and now it won't read the file in BORLAND 5, BORLAND TURBO OR DEV C++ and I've just about had it and ready to give up. I'm thinking that maybe the source was slightly different if the other compilers have different header files because borland can't find the .is_open() function as a member of fstream.


     ifstream infile("passwords.txt");
     if (!infile.is_open())
           cout << "Error opening file";


     ifstream infile("passwords.txt");
     if (!infile)
           cout << "Error opening file";

I was thinking that maybe if I could read it from it's exact location and not its reference, it might work. However, this may sound dumb too, I don't know how the syntax goes in c++ for file location. I remember double slashes but that's about it. But the program compiles without any error in ALL of the compilers. It just won't read the file. Can anybody help? I've made copies of the data file in my open drive, in the source folder, in the build folder, and on a floppy and it won't read any of them. Is there a better compiler I should be using for regular non-gui console output? I need help!1 THANKS!

By the way in response to the STRTOK being an antiquated function, I see nothing wrong with replacing delimiters anyway. In most cases, nobody would want to keep the delimiters because they're only there for delimiting the file, and second of all, I see nothing wrong w/ the original string being modified as it would be important in a lot of ways to know what is left to be split.
0
Comment
Question by:accension
  • 3
  • 2
5 Comments
 
LVL 3

Accepted Solution

by:
EarthQuaker earned 200 total points
ID: 8190476
Both syntax are correct :

ifstream infile("passwords.txt");
if (!infile.is_open())
      cout << "Error opening file";


ifstream infile("passwords.txt");
if (!infile)
      cout << "Error opening file";

Now you may want to specify the path correctly :

ifstream infile("C:/passwords.txt");
ifstream infile2("C:\\passwords.txt");

Both ways works.

Borland is not following the standard therefore it's very possible that the implementation of fstream doesn't contain .is_open()
0
 

Author Comment

by:accension
ID: 8190526
I changed it in borland and it still does not work.
0
 

Author Comment

by:accension
ID: 8190574
I AM AN IDIOT!!! Forget it. I found the solution. For anyone who really wants to know. I don't even know if I want to say it cuz I couldn't feel anymore stupid. I copied many of the text files needed however, I failed to copy a single file. passwords.txt

haha laugh at me, I know that's very stupid.
0
 

Author Comment

by:accension
ID: 8190575
Sorry to ask something so stupid.
0
 
LVL 3

Expert Comment

by:EarthQuaker
ID: 8190955
huhu ;)
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

569 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question