3
Contributors
5
Replies
7
Views
6 Years
Discussion Span
Last Post by anu07
0

There may be some non-standard functions to do so in TC++, but I would just try to open it using an fstream object then use the .is_open() method to make sure that it has opened successfully. That's kind of quick and dirty, as I'm sure there are different OS dependent ways to do that, so someone should definitely correct me if I'm off base.

0

Okay I tried with .is_open(),but an error showed up

'is_open' is not a member of 'ofstream'
now what to do?

1

Well, you want to open it using ifstream, but since your compiler is pre-standard it may not have that method of the class (I seem to remember this from another poster at one point).

What will probably work (and is also used) is to test that the ifstream object is not null:

ifstream ifs("myfile.txt");
if(!ifs)
   //file didn't open for whatever reason
Votes + Comments
worked :)
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.