answersLogoWhite

0

What are the manipulator in c plus plus?

Updated: 8/11/2023
User Avatar

Roshanjha1

Lvl 1
10y ago

Best Answer

What is a manipulator?

C++ manipulators are functions or operators that are used specifically with input and output streams in order to manipulate those streams or to insert or extract special characters. Many manipulators apply to both input and output streams but some are specific to one or the other.

The following list briefly describes all the manipulators available in C++, including those only available in C++11. Most manipulators can be found in the header, while the parameterised manipulators (those that accept arguments) will be found in the header.

Output stream manipulators

std::flush - synchronises the output buffer with the controlled output sequence

std::endl - inserts a newline character (\n) and flushes the output stream

std::ends - inserts a null character (\0) without flushing the output stream

Input stream manipulators

std::ws - extracts and discards whitespace characters from the input stream

Numerical base format manipulators ("basefield" flags)

std::dec - inserts/extracts integral numeric data with decimal notation

std::hex - inserts/extracts integral numeric data with hexadecimal notation

std::oct - inserts/extracts integral numeric data with octal notation

Floating-point format manipulators ("floatfield" flags)

std::fixed - inserts/extracts floating point values with fixed notation

std::scientific - inserts/extracts floating point values with scientific notation

std::hexfloat - inserts/extracts floating point values with hecadecimal notation (C++11 only)

std::defaultfloat - default behaviour (C++11 only)

Adjustment manipulators ("adjustfield" flags)

std::internal - output is padded to the field width by inserting fill characters at a specified internal point

std::left - output is padded to the filed width by appending fill characters

std::right - output is padded to the field width by prepending fill characters

Flags (on)

std::boolalpha - generates text values "true" and "false" for boolean values

std::showbase - generates the base for basefield values

std::showpoint - generates a decimal point for "floatfield" values

std::showpos - generates positive sign to positive values

std::skipws - ignores whitespace characters

std::unitbuf - flushes the buffer after every insertion

std::uppercase - generates upper-case letters for generated letters

Flags (off)

std::noboolalpha - does not generate text values for boolean values

std::noshowbase - does not generate the base for basefield values

std::noshowpoint - does not generate decimal point for "floatfield" values unless the decimal portion is non-zero

std::noshowpos - does not generate positive sign for positive values

std::noskipws - does not ignore whitespace characters

std::nounitbuf - does not flush the buffer afer every insertion

std::nouppercase - does not generate upper-case letters for generated letters

Parameterised manipulators

std::setiosflags - set format flags

std::resetiosflags - reset format flags

std::setbase - set basefield flag

std::setfill - set fill character

std::setprecision - set floatfield precision

std::setw - set field width

Many of these manipulators work together. For instance, the std::internal, std::left and std::rightmanipulators all work in conjunction with the std::setwand std::setfill manipulators.

All manipulators are implemented as operators which can be chained together using the insertion (<<) or extraction (>>) operators as appropriate to the stream. Excluding the parameterised manipulators, most manipulators are also implemented as functions (passing the streram as an argument). Others, including all parameterised manipulators, are implemented as members of the stream. Some, such as std::flush, are implemented all three ways; as an operator, a function and a member function.

Some examples of manipulator usage:

// set field width to 8 characters for console output

std::cout << std::setw (8); // operator

std::cout.width (8); // member method

// set precision to 16 places for floatfields

std::cout << std::setprecision (16); // operator

std::cout.precision (16); // member method

// insert newline and flush stream

std::cout << std::endl; // operator

std::endl (std::cout); // function

// flush stream

std::cout << std::flush; // operator

std::flush (std::cout); // function

std::cout.flush (); // member method

// generate hexadecimal values with base prefix

std::cout << std::showbase << std::hex; // operator

std::showbase (std::cout); // function

std::hex (std::cout); // function

More information on manipulators can be found in the sources and related links section, below.

User Avatar

Wiki User

10y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

11y ago

They are used in conjunction with the extraction and insertion operators to manipulate the formatting of stream input/output. For instance cout << boolalpha manipulates the standard output stream such that boolean values are output as "true" or "false", rather than 1 or 0. To restore the original behaviour, use cout << noboolalpha.

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

A manipulator is a function specifically meant to be used with the extraction (>>) and the insertion (<<) operators of the output and input streams. For example, endl is a manipulator that inserts a new line into the output stream and then flushes the stream. There are many such manipulators.

(See related link below for more information.)

This answer is:
User Avatar

User Avatar

Wiki User

10y ago

See related links below for a complete list of all the built-in manipulators.

This answer is:
User Avatar

Add your answer:

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

What is a user defined manipulator in c plus plus?

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&amp; operator&lt;&lt; (std::ostream&amp; st, std::ostream&amp; (*func) (std::ostream&amp;)); The second argument is the function pointer, with the following signature: std::ostream&amp; (*func) (std::ostream&amp;) 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&amp; my_manipulator (std::ostream&amp; os) { return os &lt;&lt; '\n' &lt;&lt; std::flush; } Example usage: std::cout &lt;&lt; "Hello world!" &lt;&lt; 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&amp; elipses (std::ostream&amp; os) { return os &lt;&lt; "..."; } Example usage: std::cout &lt;&lt; "Hello" &lt;&lt; elipses &lt;&lt; "world!" &lt;&lt; my_manipulator; Output: Hello...world!


Can you declare a method within a method in c or c plus plus?

C: there are no methods in C. C++: no.


What is the different of c and c plus plus?

c is procedure oriented and c++ is object oriented &amp; much newer.


How A plus B plus C plus D plus 80 plus 90 equal to 100 what is the value of A B C and D?

If a + b + c + d + 80 + 90 = 100, then a + b + c + d = -70.


In computer language C plus plus is related to?

C++ is related to C, the language from which it is derived.

Related questions

Advantages of manipulator in c plus plus?

theriyadhu


What is manipulator in c plus plus language?

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


What is the name of the 'endl' operator in c plus plus and its purpose?

endl is not an operator. Is is a stream manipulator. It inserts and end-of-line into the stream. cout &lt;&lt; "This is a test" &lt;&lt; endl &lt;&lt; "This is also a test" &lt;&lt; endl; Gives you ... This is a test This is also a test


What is the name of the 'setw' operator in c plus plus and its purpose?

setw() is not an operator, it is a parameterized stream manipulator. It sets the width of the field in the output stream which is about to be inserted. cout &lt;&lt; setw(5) &lt;&lt; 9 &lt;&lt; endl; Gives you ....9 Where each dot represents one space.


When was Manipulator EP created?

Manipulator EP was created in 1988.


When was Manipulator - album - created?

Manipulator - album - was created in 2020-12.


What is b plus b plus b plus c plus c plus c plus c?

b+b+b+c+c+c+c =3b+4c


What is c plus c plus 2c plus c plus c equal?

c + c + 2c + c + c = 6c


B plus b plus b plus c plus c plus c plus c equals?

b + b + b + c + c + c + c = 3b + 4c


Symplify c plus c plus c plus c?

4c


What is a user defined manipulator in c plus plus?

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&amp; operator&lt;&lt; (std::ostream&amp; st, std::ostream&amp; (*func) (std::ostream&amp;)); The second argument is the function pointer, with the following signature: std::ostream&amp; (*func) (std::ostream&amp;) 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&amp; my_manipulator (std::ostream&amp; os) { return os &lt;&lt; '\n' &lt;&lt; std::flush; } Example usage: std::cout &lt;&lt; "Hello world!" &lt;&lt; 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&amp; elipses (std::ostream&amp; os) { return os &lt;&lt; "..."; } Example usage: std::cout &lt;&lt; "Hello" &lt;&lt; elipses &lt;&lt; "world!" &lt;&lt; my_manipulator; Output: Hello...world!


What is c plus c plus c plus c plus c?

c + c + c + c + c = 5 * c.