std::numpunct<CharT>::truename, do_truename, falsename, do_falsename
来自cppreference.com
| 在标头 <locale> 定义
|
||
| |
(1) | |
| |
(2) | |
| |
(3) | |
| |
(4) | |
1,2) 公开成员函数,分别调用最终派生类的成员函数
do_truename 和 do_falsename。3) 返回拥有表示布尔值
true 的字符串。4) 返回拥有表示布尔值
false 的字符串。返回值
1,3) 用作
true 表示的 string_type 类型对象。std::numpunct 的标准特化返回 "true" 和 L"true"。2,4) 用作
false 表示的 string_type 类型对象。std::numpunct 的标准特化返回 "false" 和 L"false"。示例
运行此代码
#include <iomanip>
#include <iostream>
#include <locale>
struct custom_tf : std::numpunct<char>
{
std::string do_truename() const { return {'t'}; }
std::string do_falsename() const { return {'f'}; }
};
int main()
{
std::cout << std::boolalpha;
// 默认 boolalpha 输出
std::cout << "默认本地环境,\n"
" boolalpha true: " << true << "\n"
" boolalpha false: " << false << "\n\n";
// 对本地环境应用 custom_tf
std::cout.imbue(std::locale(std::cout.getloc(), new custom_tf));
std::cout << "带有改动的 numpunct 的本地环境,\n"
" boolalpha true: " << true << "\n"
" boolalpha false: " << false << '\n';
}
输出:
默认本地环境,
boolalpha true: true
boolalpha false: false
带有改动的 numpunct 的本地环境,
boolalpha true: t
boolalpha false: f