C++ streambuf::pubimbue() 函式



C++ 的std::streambuf::pubimbue()函式用於為流緩衝區設定新的區域設定。當呼叫此函式時,它會用作為引數提供的新的區域設定替換流緩衝區的當前區域設定。

此函式主要由流(例如 std::istream 或 std::ostream)用於管理與區域設定相關的操作,例如數字或日期的格式化。

語法

以下是 std::streambuf::pubimbue() 函式的語法。

locale pubimbue(const locale& _Loc);

引數

  • loc - 表示區域設定的引用。

返回值

此函式返回儲存在區域設定物件中的先前值。

異常

如果丟擲異常,則流緩衝區處於有效狀態。

資料競爭

它修改流緩衝區物件。

示例 1

在以下示例中,我們將考慮 pubimbue() 函式的基本用法。

#include <iostream>
#include <sstream>
#include <locale>
int main() {
   std::ostringstream a;
   std::locale b("");
   a.rdbuf() -> pubimbue(b);
   a << 11128932.342;
   std::cout << "Result : " << a.str() << std::endl;
   return 0;
}

輸出

讓我們編譯並執行上述程式,這將產生以下結果:

Result : 1.11289e+07
streambuf.htm
廣告