#include <iostream>
#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
void print(const boost::system::error_code&, boost::asio::deadline_timer *t, int *count)
{
if (*count < 5) {
std::cout << "print: " << "hello world times: " << *count << std::endl;
++(*count);
t->expires_at(t->expires_at() + boost::posix_time::seconds(1));
t->async_wait(boost::bind(print, boost::asio::placeholders::error, t, count));
}
}
int main()
{
struct tm *myTm;
char myDate[21];
int count = 0;
time_t myTime = time(NULL);
strftime(myDate, 21, "%Y-%m-%d %H:%M:%S", localtime(&myTime));
std::cout << myDate << std::endl;
boost::asio::io_service io;
boost::asio::deadline_timer t(io, boost::posix_time::seconds(1));
t.async_wait(boost::bind(print, boost::asio::placeholders::error, &t, &count));
io.run();
myTime = time(NULL);
strftime(myDate, 21, "%Y-%m-%d %H:%M:%S", localtime(&myTime));
std::cout << myDate << std::endl;
return 0;
}