// Test case to demonstrate that operator<< of // boost::posix_time::ptime doesn't take a set ios::failbit into // account correctly but instead prints itself everytime. // Compile and run as follows: // g++ ptime-operator.cpp -o ptime-operator // ./ptime-operator #include #include #include using namespace std; int main(int /*argc*/, char** /*argv*/) { boost::posix_time::ptime p = boost::posix_time::microsec_clock::local_time(); // The following line should appear cout << "Should appear: Text. And Date: " << p << " Boost v" << int(BOOST_VERSION) << endl; cout.clear (std::ios::failbit); // set ios::failbit -> no more output // The following line should *not* appear, BUT the time is printed // anyway! (That's the bug.) cout << "Should not appear: Text. And Date: " << p << endl; cout.clear (); // remove ios::failbit -> resume output // The following line should appear again cout << "\nThis line should appear (but no single date above): Text. And Date: " << p << std::endl; }