C++ Tutorial: User Defined Manipulators

In C++, user can define and use manipulator similar to built in manipulators as per the users’ used and desire to control the format of input and output. Similar to the predefined built manipulators use can define non parameterized as well as parameterized manipulators. The syntax for designing manipulator is as follows:

 

ostream& manipulator_name(ostream& output, args..){
//body of user defined manipulators
return output;
}

The manipulator_name is the name of the user defined manipulator, ostream & ouput is the manipulator called and stream cascading object and args is the number of arguments for parameterized manipulators. The following example illustrates how to use parameterized custom manipulator.

Loading…
#include

#include


using std::cin;

using std::cout;

using std::endl;

using std::ostream;

using std::flush;


class UD_Manip

{

private:

int width, precision;

char fill;

public:

UD_Manip(int W, int P, char F){

width = W;

precision = P;

fill = F;

}

friend ostream& operator

Loading...