Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Does ifstream know why it is unable to open file?

Reply
Thread Tools

Does ifstream know why it is unable to open file?

 
 
Alex Vinokur
Guest
Posts: n/a
 
      08-13-2003
-------------------------------
ifstream fin ("foo.txt");
if (!fin) cout << "Warning: Unable to open file" << endl;
-------------------------------

There are several reasons for getting that warning :
* foo.txt doesn't exist
* foo.txt exists but is busy
* etc.

Can ifstream know why it is unable to open the file?

=====================================
Alex Vinokur
(E-Mail Removed)
http://mathforum.org/library/view/10978.html
=====================================


 
Reply With Quote
 
 
 
 
Frank Schmitt
Guest
Posts: n/a
 
      08-20-2003
"Alex Vinokur" <(E-Mail Removed)> writes:

> -------------------------------
> ifstream fin ("foo.txt");
> if (!fin) cout << "Warning: Unable to open file" << endl;
> -------------------------------
>
> There are several reasons for getting that warning :
> * foo.txt doesn't exist
> * foo.txt exists but is busy
> * etc.
>
> Can ifstream know why it is unable to open the file?


If it knows, it's platform-dependent (as Victor already
pointed out).
If you don't care about portability, You might want to check
if your implementation sets errno upon failure - some of them do.

HTH & kind regards
frank

--
Frank Schmitt
4SC AG phone: +49 89 700763-0
e-mail: frank DOT schmitt AT 4sc DOT com
 
Reply With Quote
 
 
 
 
Kevin Goodsell
Guest
Posts: n/a
 
      08-20-2003
Frank Schmitt wrote:
> "Alex Vinokur" <(E-Mail Removed)> writes:
>
>>Can ifstream know why it is unable to open the file?

>
>
> If it knows, it's platform-dependent (as Victor already
> pointed out).
> If you don't care about portability, You might want to check
> if your implementation sets errno upon failure - some of them do.
>


Why would checking errno require not caring about portability? errno is
standard. Either the function will set it or not. It's easy to check and
use it if it has a meaningful value.

But I don't know how common it is for implementations to set errno in
this case.

-Kevin
--
My email address is valid, but changes periodically.
To contact me please use the address from a recent posting.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: how to open a file in some application using Tkinter i am usingTKINTER to create GUI application i want to know how to open a worddocument in open office or any other applicatio Fredrik Lundh Python 1 01-09-2008 10:40 AM
why why why why why Mr. SweatyFinger ASP .Net 4 12-21-2006 01:15 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
I know, I know, I don't know Andries Perl Misc 3 04-23-2004 02:17 AM
Can't Open .exe Files - Does Anyone know Why ? chris Computer Support 5 04-04-2004 01:18 PM



Advertisments