answersLogoWhite

0


Best Answer

A user-defined manipulator is a function which can be passed as an argument to the stream insertion or extraction operator overloads. For example, the output stream insertion operator has the following overload:

std::ostream& operator<< (std::ostream& st, std::ostream& (*func) (std::ostream&));

The second argument is the function pointer, with the following signature:

std::ostream& (*func) (std::ostream&)

Any function that matches this signature can be used as a manipulator. For instance, the following user-defined manipulator does exactly the same job as the std::endl manipulator:

std::ostream& my_manipulator (std::ostream& os)

{

return os << '\n' << std::flush;

}

Example usage:

std::cout << "Hello world!" << my_manipulator;

You can, of course, provide your own implementations to perform any type of manipulation. For example, suppose you want a manipulator that inserts an elipses into an output stream:

std::ostream& elipses (std::ostream& os)

{

return os << "...";

}

Example usage:

std::cout << "Hello" << elipses << "world!" << my_manipulator;

Output:

Hello...world!

User Avatar

Wiki User

9y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is a user defined manipulator in c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Can a C plus plus user defined function return a value?

Absolutely. Indeed, any function (user-defined or built-in) that does not return a value is not really a function, it is simply a procedure.


How do the IO facilities in C plus plus differ from those in C?

The C standard library IO facilities are not extensible. For instance, the printf() and scanf() functions cannot handle user-defined types. However, the C++ standard library provides IO streams with insertion and extraction operators (&lt;&lt; and &gt;&gt;) that can be overloaded to support any user-defined type.


What is use of user defined data in c?

to create user defined functions the user defined data is needed nd its useful to the programmer to create its own data.


What is clear in c plus plus?

clear() is an inbuilt function defined in c++ defined in conio.h. It is used for clearing the console. The systax is:clear();


Why c plus plus is more user friendly?

More user friendly than what? Please restate the question.

Related questions

User defined data type in c plus plus?

Use "typedef" : both in C and C++.


Advantages of manipulator in c plus plus?

theriyadhu


Can a C plus plus user defined function return a value?

Absolutely. Indeed, any function (user-defined or built-in) that does not return a value is not really a function, it is simply a procedure.


What is manipulator in c plus plus language?

Manipulators are functions that change the formatting parameters on character streams.


In c programming is main predefined or user defined?

main is predeclared and user defined.


How do the IO facilities in C plus plus differ from those in C?

The C standard library IO facilities are not extensible. For instance, the printf() and scanf() functions cannot handle user-defined types. However, the C++ standard library provides IO streams with insertion and extraction operators (&lt;&lt; and &gt;&gt;) that can be overloaded to support any user-defined type.


What is use of user defined data in c?

to create user defined functions the user defined data is needed nd its useful to the programmer to create its own data.


What are the pre-defined function in c plus plus?

The C++ standard library contains all the pre-defined functions.


What is mapping exception in c plus plus?

There is no such exception in C++. It's probably a 3rd party or user-defined exception. Examine the call-stack to determine where the exception was caught -- that should help you determine where the exception was thrown.


What is clear in c plus plus?

clear() is an inbuilt function defined in c++ defined in conio.h. It is used for clearing the console. The systax is:clear();


Why c plus plus is more user friendly?

More user friendly than what? Please restate the question.


What does tbuffer mean in c plus plus?

There is no such keyword or data type known as tbuffer in C++. It's most likely an user-defined identifier, possibly a text buffer. But without knowing its actual type or its context it's impossible to say what it means.