Hello!
I'm trying to write some content to a new file using
boost::stream class.
Unfortunately errors/failures during opening the file are ignored by
boost library.
Here is a snippet:
using namespace boost::iostreams;
stream stream( "/wrong.txt" );
std::cout << stream.fail() << ' ' << stream.bad() << std::endl;
stream.exceptions( std::ios::badbit | std::ios::failbit );
stream << "test" << std::endl;
stream.close();
Program is started as not root user and have not access for file /
wrong.txt.
It should throw an exception, but instead of this:
- console prints: 0 0
- none exception is thrown
- file /wrong.txt is not created
Similar piece of code using std::ofstream works as I expect:
using namespace std;
ofstream stream( "/wrong.txt" );
std::cout << stream.fail() << ' ' << stream.bad() << std::endl;
stream.exceptions( std::ios::badbit | std::ios::failbit );
stream << "test" << std::endl;
stream.close();
- console prints: 1 0
- exception is thrown
I cannot believe that boost::iostreams has such obvious bug and just
ignore failures!
I have to do something wrong. But what?
Regards,
Mariusz Wojtysiak