Coupon Accepted Successfully!


User-Defined Manipulators

The programmer can also define his or her own manipulator according to the requirement of the program. The syntax for defining manipulator is as follows.

ostream & m_name ( ostream & o )




return o;


The m_name is the name of the manipulator.

3.47 Write a program to create manipulator equivalent to ‘\t’. Use it in the program and format the output.


Explanation: Figure illustrates the working of the program.


Description: 144937.png

Working of tab manipulator

In the above program, tab named manipulator is defined. The definition of tab manipulator contains the escape sequence ‘\t’. Whenever we call the tab manipulator, the ‘\t’ is executed and we get the effect of tab.

3.48 Write a program to display a message using manipulator.


Explanation: In the above program, two manipulators N and P are created. When called, N displays the message “Negative number” and P displays the message “Positive number”.

Test Your Skills Now!
Take a Quiz now
Reviewer Name