此函數通過首先構造一個類型為basic_istream::sentry
的對象(noskipws
設置為 false
)來訪問輸入序列。然後(如果 sentry
對象是 true
),它調用money_get::get
(使用流的所選地區)來執行提取和解析操作,並相應地調整流的內部狀態標誌。
最後,它在返回之前銷毀 sentry
對象。
它用於從應用程式於輸入流的字元中提取字元,並將它們解釋為貨幣運算式,存儲為mon
的值。
聲明
以下是 std::get_money
函數的聲明。
參數
mon
− 存儲貨幣值的對象,moneyT
應該是long double
或者basic_string
的一個實例。intl
−true
表示國際化,否則為false
。這在內部用於實例化適當的多用途類。
示例
例在下面的例子中說明了 get_money
函數的用法。
#include <iostream>
#include <iomanip>
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;
}
編譯和運行上面的程式,將產生以下結果 -
Please, enter the price: 100
The price entered is: 100
上一篇:
std::setw()函數
下一篇:
std::put_money()函數