what are manipulators in c++

Manipulators in C++ are used to format the output of data that is displayed on the console. They are functions or objects that modify the stream buffer associated with the standard input/output streams. Here are some common manipulators in C++:

  1. setw(int width):
  2. Sets the field width of the next input/output operation to the specified number of characters.

  3. setprecision(int n):

  4. Sets the precision of floating-point numbers to the specified number 'n'.

  5. setfill(char ch):

  6. Sets the fill character for the field width.

  7. setiosflags(int flags):

  8. Sets various format flags specified by the 'flags' parameter.

  9. resetiosflags(int flags):

  10. Resets the format flags specified by the 'flags' parameter.

  11. setbase(int base):

  12. Sets the basefield format flag for the stream.

  13. setf(int flags):

  14. Sets various format flags specified by the 'flags' parameter.

  15. unsetf(int flags):

  16. Unsets the format flags specified by the 'flags' parameter.

  17. hex, oct, dec:

  18. Sets the basefield to hexadecimal, octal, or decimal respectively.

  19. boolalpha, noboolalpha:

    • Controls the output for boolean values to be either textual (true/false) or numeric (1/0).
  20. showpoint, noshowpoint:

    • Shows or hides the decimal point and trailing zeros for floating-point values.
  21. showpos, noshowpos:

    • Shows or hides the positive sign for positive values.
  22. uppercase, nouppercase:

    • Converts alphabetic characters to uppercase or leaves them as they are.
  23. skipws, noskipws:

    • Enables or disables skipping leading whitespaces during input operations.
  24. ws:

    • Skips leading whitespaces during input operations.

These manipulators can be used in conjunction with the insertion (<<) and extraction (>>) operators to control the formatting of input and output streams.