I am confused with the C++ function std::get_money
defined in the <iomanip>
header file. What is the use of get_money
as per programming concept?
I have the following code using std::get_money
.
#include <iostream> // std::cin, std::cout
#include <iomanip> // std::get_money
int main ()
{
long double price;
std::cout << "Please, enter the price: ";
std::cin >> std::get_money(price);
if (std::cin.fail()) std::cout << "Error reading price\n";
else std::cout << "The price entered is: " << price << '\n';
return 0;
}
When I typed in an input of 100.25 it returned 100. What is the relation between the output and monetary format? I read this reference but cannot understand the relation. The same confusion is present with std::put_money
, std::get_time
, and std::put_time
.
What are some examples of its actual use?
std::put_money
: https://mcmap.net/q/1917633/-c-currency-output – Civillydouble
to represent prices. – Hasbeen