Example 1

In this example, we are using the boost APIs to output the current date and time to stdout, as follows:

#include <iostream>
#include <boost/chrono.hpp>

int main(void)
{
using namespace boost::chrono;

std::cout << "Date/Time: " << system_clock::now() << ' ';
return 0;
}

As shown in the preceding example, the current date and time are outputted to stdout as the total number of nanoseconds since the Unix Epoch (January 1, 1970). In addition to including boost in your source code, you must also link your application against the boost libraries. In this case, we needed to link against the following:

-lboost_chrono -lboost_system -lpthread

An example of how this is done can be seen in the CMakeLists.txt file that was downloaded with this recipe. Once these libraries have been linked to your project, your code will be able to leverage the APIs inside them. This extra step is why header-only libraries can be so useful when creating your own libraries as they obviate the need for additional linking.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset