How to do it...

In this section, we will write a little game that prompts the user to enter a specific word. The time that the user needs to type this word into the keyboard is measured and displayed in multiple time units:

  1. At first, we need to include all the necessary headers. For reasons of comfort, we declare that we use the std namespace by default:
      #include <iostream>      #include <chrono>      #include <ratio>      #include <cmath>      #include <iomanip>      #include <optional>            using namespace std;
  1. The chrono::duration as a type for time durations usually refers to multiples or fractions of seconds. All the STL time duration units refer to integer typed duration specializations. In this recipe, we are going to specialize on double. In the recipe after ...

Get C++17 STL Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.