public member function
<locale>
std::locale::combine
template <class Facet> locale combine (const locale& x) const;
Construct copy of locale modifying one facet
Returns a locale object constructed from a copy of *this
, except for the facet specified by template parameter Facet, which is taken from x.
Throws runtime_error if x does not have the facet specified by Facet defined.
The resulting locale has no name.
参数
- x
- A locale objects whose facet Facet is used by the new locale.
返回值
The resulting locale object, which has no name.
示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
// locale::combine example
#include <iostream> // std::cout
#include <locale> // std::locale, std::num_put
int main ()
{
std::locale loc(""); // initialized to environment's locale
// combine loc with the "C" locale for num_put
loc = loc.combine< std::num_put<char> > (std::locale::classic());
std::cout.imbue(loc);
std::cout << 3.14159 << '\n';
return 0;
}
|
Output (no matter the environment's locale)
数据竞争
The locale object is modified.
异常安全
基本保证:如果抛出异常,对象处于有效状态。
It throws an exception of type runtime_error if x is not a locale with Facet defined.