Boost logo

Boost Users :

Subject: [Boost-users] [Iostreams] How to check whether file has ben opened?
From: Daniel Eiband (eiband_at_[hidden])
Date: 2010-03-29 08:40:30


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?

Thanks,

Daniel


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