User-defined Manipulators
Explore how to implement user-defined manipulators in C++ such as tab for tab spacing and roman for converting Roman numeral strings to decimal values. Understand the mechanisms behind manipulators, function pointers, and operator overloading to enhance output stream formatting and handling.
We'll cover the following...
Problem
Write a program to create two user-defined manipulators called tab and roman. The tab manipulator should output a \t to the output stream and the roman manipulator should receive a roman string as an argument and send its decimal equivalent to the output stream.
Coding solution
Here is a solution to the problem above.
Explanation
To understand how to develop a zero-argument manipulator we need to understand the internal working of some existing manipulator, say endl. endl is simply a function that takes as its argument an ostream reference. The ...