std::numpunct<CharT>:: truename, do_truename, falsename, do_falsename
From cppreference.net
C++
Text processing library
| Localization library | |||||||||||||||||||||||||
| Regular expressions library (C++11) | |||||||||||||||||||||||||
| Formatting library (C++20) | |||||||||||||||||||||||||
| Null-terminated sequence utilities | |||||||||||||||||||||||||
| Byte strings | |||||||||||||||||||||||||
| Multibyte strings | |||||||||||||||||||||||||
| Wide strings | |||||||||||||||||||||||||
| Primitive numeric conversions | |||||||||||||||||||||||||
|
|||||||||||||||||||||||||
| Text encoding identifications | |||||||||||||||||||||||||
|
|||||||||||||||||||||||||
Localization library
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
std::numpunct
| Member functions | ||||
|
numpunct::truename
numpunct::do_truename
numpunct::falsename
numpunct::do_falsename
|
|
ヘッダー
<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)
string_type
型のオブジェクトで、
true
の表現として使用するもの。
std::numpunct
の標準特殊化は
"true"
および
L
"true"
を返す。
2,4)
string_type
型のオブジェクトで、
false
の表現として使用するもの。
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