
- The C Standard Library
- The C Standard Library
- The C++ Standard Library
- C++ Library - Home
- C++ Library - <fstream>
- C++ Library - <iomanip>
- C++ Library - <ios>
- C++ Library - <iosfwd>
- C++ Library - <iostream>
- C++ Library - <istream>
- C++ Library - <ostream>
- C++ Library - <sstream>
- C++ Library - <streambuf>
- C++ Library - <atomic>
- C++ Library - <complex>
- C++ Library - <exception>
- C++ Library - <functional>
- C++ Library - <limits>
- C++ Library - <locale>
- C++ Library - <memory>
- C++ Library - <new>
- C++ Library - <numeric>
- C++ Library - <regex>
- C++ Library - <stdexcept>
- C++ Library - <string>
- C++ Library - <thread>
- C++ Library - <tuple>
- C++ Library - <typeinfo>
- C++ Library - <utility>
- C++ Library - <valarray>
- The C++ STL Library
- C++ Library - <array>
- C++ Library - <bitset>
- C++ Library - <deque>
- C++ Library - <forward_list>
- C++ Library - <list>
- C++ Library - <map>
- C++ Library - <queue>
- C++ Library - <set>
- C++ Library - <stack>
- C++ Library - <unordered_map>
- C++ Library - <unordered_set>
- C++ Library - <vector>
- C++ Library - <algorithm>
- C++ Library - <iterator>
- C++ Programming Resources
- C++ Programming Tutorial
- C++ Useful Resources
- C++ Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
C++ iomanip Library - put_money Function
Description
This function accesses the output sequence by first constructing an object of type basic_ostream::sentry. Then (if evaluating the sentry object is true), it calls money_put::put (using the stream's selected locale) to perform both the formatting and the insertion operations, adjusting the stream's internal state flags accordingly. Finally, it destroys the sentry object before returning.
It is used to inserts the representation of mon as a monetary value into the output stream it is applied to.
Declaration
Following is the declaration for std::put_money function.
template <class moneyT> /*unspecified*/ put_money (const moneyT& mon, bool intl = false);
Parameters
mon − Monetary value. moneyT shall be either long double or a basic_string instantiation.
intl − true for international representations, false otherwise. This is used internally to instantiate the proper moneypunct class.
Return Value
It returns unspecified. This function should only be used as a stream manipulator.
Errors are signaled by modifying the stream's internal state flags −
flag | error |
---|---|
failbit | The function failed to format mon (it may also be set if the construction of sentry failed). |
badbit | Either the insertion on the stream failed, or some other error happened (such as when this function catches an exception thrown by an internal operation).When set, the integrity of the stream may have been affected. |
Exceptions
Basic guarantee − if an exception is thrown, the object is in a valid state.
Basic guarantee − if an exception is thrown, the object is in a valid state.
It throws an exception of member type failure if the resulting error state flag is not goodbit and member exceptions was set to throw for that state.
Any exception thrown by an internal operation is caught and handled by the function, setting badbit. If badbit was set on the last call to exceptions, the function rethrows the caught exception.
Data races
Modifies the stream object where it is inserted.
Concurrent access to the same stream object may cause data races, except for the standard stream objects (cout, cerr, clog, wcout, wcerr and wclog) when these are synchronized with stdio (in this case, no data races are initiated, although no guarantees are given on the order in which characters from multiple threads are inserted).
Example
In below example explains about put_money function.
#include <iostream> #include <iomanip> int main () { std::cout << "Price:" << std::put_money(10.50L) << '\n'; return 0; }
Let us compile and run the above program, this will produce the following result −
Price:10