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

source code of boost/libs/chrono/example/io_ex2.cpp