io_ex2.cpp 901 B

123456789101112131415161718192021222324252627282930313233343536
  1. // io_ex2.cpp ----------------------------------------------------------//
  2. // Copyright 2010 Howard Hinnant
  3. // Copyright 2010 Vicente J. Botet Escriba
  4. // Distributed under the Boost Software License, Version 1.0.
  5. // See http://www.boost.org/LICENSE_1_0.txt
  6. /*
  7. This code was adapted by Vicente J. Botet Escriba from Hinnant's html documentation.
  8. Many thanks to Howard for making his code available under the Boost license.
  9. */
  10. #include <boost/chrono/chrono_io.hpp>
  11. #include <sstream>
  12. #include <boost/assert.hpp>
  13. int main()
  14. {
  15. using namespace boost::chrono;
  16. std::istringstream in("5000 milliseconds 4000 ms 3001 ms");
  17. seconds d(0);
  18. in >> d;
  19. BOOST_ASSERT(in.good());
  20. BOOST_ASSERT(d == seconds(5));
  21. in >> d;
  22. BOOST_ASSERT(in.good());
  23. BOOST_ASSERT(d == seconds(4));
  24. in >> d;
  25. BOOST_ASSERT(in.fail());
  26. BOOST_ASSERT(d == seconds(4));
  27. return 0;
  28. }