Example of Defining an APP Parameterized Manipulator

In the following example, the macro IOMANIPdeclare is called with the user-defined class my_class as an argument. One of the classes that is produced, OAPP(my_class), is used to define the manipulator pre_print.

//   Creating and using parameterized manipulators
#include <iomanip.h>
// declare class
class my_class {
   public:
      char * s1;
      const char c;
      unsigned short ctr;
      my_class(char *theme, const char suffix,
           unsigned short times):
           s1(theme), c(suffix), ctr(times) {}
   }; 
// print a character an indicated number of times
// followed by a string
ostream& produce_prefix(ostream& o, my_class mc) {
   for (register i=mc.ctr; i; --i) o << mc.c ;
   o << mc.s1;
   return o;
}
IOMANIPdeclare(my_class); 
// define a manipulator for the class my_class
OAPP(my_class) pre_print=produce_prefix;
void main() {
   my_class obj("Hello",'-',10);
   cout << pre_print(obj) << endl;
}

This program produces the following output:

----------Hello