Boost logo

Boost Users :

Subject: Re: [Boost-users] [Iostreams] How to check whether file has ben opened?
From: Roland Bock (rbock_at_[hidden])
Date: 2010-03-30 06:04:07


Daniel Eiband wrote:
> Hi, I'm using Boost 1.42.0 and I have the same problem like vandamme
> described in this post at the end:
>
> http://groups.google.com/group/boost-list/browse_thread/thread/c290c987bf1fab3b
>
>
> The following code will assert if the file "test" does not exist:
>
> std::string filename("test");
> boost::iostreams::stream<boost::iostreams::file_source> file;
>
> file.open(filename.c_str());
> if (file.is_open())
> {
> // assert fires if file "test" does not exist
> assert(boost::filesystem::exists(filename));
> }
>
> The indirect_streambuf doesn't check the device and just returns true
> if open has been called (independent of whether open has been
> successful).
>
> If I use the std::ifstream supplied with MSVC 9.0 is_open() returns
> false if the file does not exits. Checked by replacing file declaration
> with:
>
> std::ifstream file;
>
> Is this a bug? If not how can I test whether opening the stream
> succeeds?
>
I think you should file a bug. This can't be the intended behavior.

Regards,

Roland


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net