std::numpunct<CharT>::truename, do_truename, falsename, do_falsename
From cppreference.com
| ヘッダー <locale> で定義 |
||
| public: string_type truename() const; |
(1) | |
| public: string_type falsename() const; |
(2) | |
| protected: virtual string_type do_truename() const; |
(3) | |
| protected: virtual string_type do_falsename() const; |
(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; // default boolalpha output std::cout << "Default locale,\n" " boolalpha true: " << true << "\n" " boolalpha false: " << false << "\n\n"; // with custom_tf applied to locale std::cout.imbue(std::locale(std::cout.getloc(), new custom_tf)); std::cout << "Locale with modified numpunct,\n" " boolalpha true: " << true << "\n" " boolalpha false: " << false << '\n'; }
出力
Default locale, boolalpha true: true boolalpha false: false Locale with modified numpunct, boolalpha true: t boolalpha false: f