?
Solved

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

Posted on 2003-03-23
5
Medium Priority
?
226 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in August's Course of the Month

August's CompTIA IT Fundamentals course includes 19 hours of basic computer principle modules and prepares you for the certification exam. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
Suggested Courses

770 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