Using time I/O manipulators
Similar to the monetary I/O manipulators that we discussed in the previous recipe, the C++11 standard provides manipulators that control the writing and reading of time values to and from streams, where time values are represented in the form of a std::tm
object that holds a calendar date and time. In this recipe, you will learn how to use these time manipulators.
Getting ready
Time values used by the time I/O manipulators are expressed in std::tm
values. You should be familiar with this structure from the <ctime>
header.
You should also be familiar with locales and how to set them for a stream. This topic was discussed in the Using localized settings for streams recipe. It is recommended that you read that recipe before continuing.
The manipulators discussed in this recipe are available in the std
namespace, in the <iomanip>
header.
How to do it...
To write a time value to an output stream, you should perform the following...