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

C++




// C++ program to illustrate the use of get_money functio
#include <iomanip>
#include <ios>
#include <iostream>
using namespace std;
  
// driver code
int main()
{
    long double price;
  
    cout << "Enter the price: ";
    // getting price using get_money function
    cin >> get_money(price);
  
    if (cin.fail()) {
        cout << "Sorry! We had an error reading the price"
             << endl;
    }
    else {
        cout << "The price is: " << price << endl;
    }
    
    return 0;
}


Output

Enter the price: 22
The price is: 22

< iomanip > Header in C++

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.

Similar Reads

C++ Functions

The following table lists the commonly used functions:...

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....

2. resetiosflags in C++

...

3. setbase 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....

4. setw in C++

...

5. setfill in C++

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

6. setprecision in C++

...

7. get_money 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....

8. put_money in C++

...

9. get_time 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....

10. put_time in C++

...

11. quoted 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....