How to do it...

In this section, we are going to print the same image from the wall poster as a little piece of ASCII art in the terminal:

  1. First, we include all the headers and declare that we use the std namespace:
      #include <iostream>      #include <algorithm>      #include <iterator>      #include <complex>      #include <numeric>      #include <vector>            using namespace std;
  1. The Mandelbrot set and formula operate on complex numbers. So, we define a type alias, cmplx to be of class std::complex, specializing on double values.
      using cmplx = complex<double>;
  1. It is possible to hack together all the code for an ASCII Mandelbrot image in something around 20 lines of code, but we will implement each logical step in a separate form, and then assemble all the steps ...

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.