How to do it...

We will play with std::ostream_iterator by enabling for combination with a new custom class and have a look into its implicit conversion capabilities, which can help us with printing:

  1. The include files come first and then we declare that we use the std namespace by default:
      #include <iostream>      #include <vector>      #include <iterator>      #include <unordered_map>      #include <algorithm>            using namespace std;
  1. Let's implement a transformation function, which maps numbers to strings. It shall return "one" for the value 1, "two" for the value 2, and so on:
      string word_num(int i) {
  1. We fill a hash map with the mappings we need in order to access them later:
          unordered_map<int, string> m {              {1, "one"}, {2, "two"}, {3, "three"}, {4, ...

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.