此函數(shù)首先通過構(gòu)造一個類型為 basic_ostream::sentr 的對象來訪問輸出序列。
然后(如果計(jì)算 sentry 對象是 true),它調(diào)用 money_put::put(使用流的選擇的區(qū)域設(shè)置)來執(zhí)行格式化和插入操作,相應(yīng)地調(diào)整流的內(nèi)部狀態(tài)標(biāo)志。
最后,它在返回之前銷毀 sentry 對象。
它用于將貨幣的表示作為貨幣值插入到其應(yīng)用的輸出流中。
以下是std::put_money函數(shù)的聲明。
template <class moneyT>
/*unspecified*/ put_money (const moneyT& mon, bool intl = false);
mon ? 貨幣值。moneyT應(yīng)該是long double或者basic_string一個實(shí)例。intl ? true表示國際化,否則為false。這在內(nèi)部用于實(shí)例化適當(dāng)?shù)亩嘤猛绢悺?/li>它返回未指定(unspecified),此函數(shù)應(yīng)僅用作流操縱器。
下面的例子解釋了 put_money() 函數(shù)用法。
#include <iostream>
#include <iomanip>
int main () {
std::cout << "Price:" << std::put_money(10.50L) << '/n';
return 0;
}
編譯和運(yùn)行上面的程序,將產(chǎn)生以下結(jié)果 -
Price:10