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, "four"}, ...

Get Expert C++ Programming now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.