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
|
|
Definiert im Header
<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)
Öffentliche Memberfunktion, ruft die Memberfunktionen
do_truename
und
do_falsename
der am stärksten abgeleiteten Klasse entsprechend auf.
3)
Gibt den String zurück, der als Darstellung des booleschen Wertes
true
verwendet werden soll.
4)
Gibt den String zurück, der als Darstellung des booleschen Wertes
false
verwendet werden soll.
Rückgabewert
1,3)
Das Objekt vom Typ
string_type
, das als Darstellung von
true
verwendet werden soll. Die Standard-Spezialisierungen von
std::numpunct
geben
"true"
und
L
"true"
zurück.
2,4)
Das Objekt vom Typ
string_type
, das als Darstellung von
false
verwendet werden soll. Die Standard-Spezialisierungen von
std::numpunct
geben
"false"
und
L
"false"
zurück.
Beispiel
Diesen Code ausführen
#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'; }
Ausgabe:
Default locale, boolalpha true: true boolalpha false: false Locale with modified numpunct, boolalpha true: t boolalpha false: f