VOOZH about

URL: https://www.geeksforgeeks.org/cpp/iomanip-in-cpp/

⇱ < iomanip > Header in C++ - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

< iomanip > Header in C++

Last Updated : 23 Jul, 2025

In C++, the <iomanip> header file defines the manipulator functions that are used to manipulate the format of the input and output of our program. It is a part of the input/output library in C++. In this article, we will discuss the functions and facilities provided in the <iomanip> header file in C++ with examples.

C++ <iomanip> Functions

The following table lists the commonly used <iomain> functions:

S. No.Function

Description

Syntax

1resetiosflagsThis function is used to reset or clear ios_base flags specified by the parameter mask.resetiosflags (ios_base :: fmtflags mask);
2setiosflagsThis function is used to set the ios_base flags specified by the parameter mask.setiosflags(ios_base :: fmtflags mask);
3

setbase

This function is used to set the base according to the argument specified as a parameter to the function.setbase(int base);
4

setfill

This function is used to change the fill character. It is used to set the fill according to the character specified as a parameter to the function.setfill(char c);
5

setprecision

This function is used to change the floating-point precision based on the precision specified as a parameter to the function.setprecision(int n);
6

setw

This function is used to change the width of the next input/output field based on the width specified as a parameter to the function.setw(int n);
7

get_money

This function is used to parse a monetary value.get_money(moneyT& mon, bool intl = false);
8

put_money

This function is used to format and output a monetary value.put_money(const moneyT& mon, bool intl = false);
9

get_time

This function is used to parse a date/time value according to the specified format.get_time(tm* tmb, const charT* fmt);
10

put_time

This function is used to format and output a date/time value according to the format specified.put_time(const tm* tmb, const charT* fmt);
11

quoted

This function is used to insert and extract quoted strings with embedded space.quoted(const CharT* s, CharT delim = CharT(' " '), CharT escape = CharT('\\'));

Lets discuss each of these functions one by one.

1. setiosflags in C++

The setiosflag function is used to set the ios_base flags that are specified by its parameter for the stream it is used on.

Syntax of setiosflags

 setiosflags (ios_base::fmtflags mask);

Here,

  • mask: It is actually the flag which we have to set.

Example of setiosflags


Output
Setting the showbase flag : 0x3c

2. resetiosflags in C++

The resetiosflags function in C++ is used to reset or clear ios_base flags specified by parameter mask for the stream it is used on.

Syntax of resetiosflags

resetiosflags (ios_base::fmtflags mask);

where,

  • mask: It is the actual flag to be reset.

Example of reseriosflags


Output
Before resetting the showbase flag : 0X64
After resetting the showbase flag : 64

3. setbase in C++

The setbase function is used to set the base according to the argument specified as a parameter to the function.

Syntax of setbase

setbase(int base);

Here,

  • base: It is the base of the numerical values.

Example :


Output
Number before setting the base : 30
Number after setting the base to octal : 36

4. setw in C++

The setw function is used to change the width of the next input/output field based on the width specified as a parameter to the function.

Syntax of setw

setw(int n);

Here,

  • n: It is an integer argument specifying the number of characters to be used as width.

Example of setw


Output
Original Number : 30
Number after setting width : 30

5. setfill in C++

The setfill function is used to change the fill character that is used when the span of the printed data is less than the span specified using setw. It is used to set the fill according to the character specified as a parameter to the function.

Syntax of setfill

setfill (char c);

Here,

  • c: It is a variable of character type corresponding to which the fill is set.

Example of setfill


Output
Original number : 30
Number after setting the fill character to $ : $$$$$$$$$$$$$$$$$$30

6. setprecision in C++

The setprecision function is used to change the floating-point precision of the float and double data type based on the precision specified as a parameter to the function.

Syntax of the setprecision

setprecision(int n);

Here,

  • n: It is an integer argument specifying the new precision.

Example of setprecision


Output
Original Number : 10.6126
Number after setting precision to 3 : 10.6

7. get_money in C++

The get_money function in C++ is used to parse a monetary value from the input stream.

Syntax of get_money

get_money(moneyT& mon, bool intl = false);

Here,

  • mon: represents the object where the monetary value will be stored
  • intl: Boolean value which is true of international representation and false otherwise.

Example of get_money


Output

Enter the price: 22
The price is: 22

8. put_money in C++

The put_money function is the counterpart of get_money function is used to format and output a monetary value to the given output stream.

Syntax of put_money

put_money(const moneyT& mon, bool intl = false);

Here,

  • mon: represents the object where the monetary value will be stored
  • intl: Boolean value which is true of international representation and false otherwise.

Example of put_money


Output
The amount is : 101

9. get_time in C++

The get_time function in C++ is used to parse a date and time value from the input stream according to the specified format.

Syntax get_time

get_time(tm* tmb, const charT* fmt);

Here,

  • tmb: It is a pointer to the structure where the date and time information will be stored
  • fmt: It represents the desired format of date and time.

Example of get_time


Output

Enter the time: 10:15:03
The time entered is: 
10 hours 15 minutes 3 seconds 

10. put_time in C++

The put_time function is used to format and output a date/time value according to the format specified for the given stream.

Syntax of put_time

put_time(const tm* tmb, const charT* fmt);

Here,

  • tmb: It is a pointer to the structure where the date and time information will be stored
  • fmt: It represents the desired format of date and time.

Example of put_time


Output
Current System Time: 05:45:55 PM

11. quoted in C++

The quoted function in C++ is used to insert and extract quoted strings with embedded space.

Syntax of quoted

quoted(const CharT* s, CharT delim = CharT(' " '), CharT escape = CharT('\\'));

Here,

  • s: String to be printed.
  • delim: Character to be used as delimiter.
  • escape: Character to be used as escape sequence.

Example of quoted


Output
Original string: Hello World!
String after quoted : "Hello World!"
Comment
Article Tags: