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
|
|
Definido en el encabezado
<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)
Función miembro pública, llama a las funciones miembro
do_truename
y
do_falsename
de la clase más derivada respectivamente.
3)
Devuelve la cadena que se utilizará como representación del valor booleano
true
.
4)
Devuelve la cadena que se utilizará como representación del valor booleano
false
.
Valor de retorno
1,3)
El objeto de tipo
string_type
que se utilizará como representación de
true
. Las especializaciones estándar de
std::numpunct
devuelven
"true"
y
L
"true"
.
2,4)
El objeto de tipo
string_type
que se utilizará como representación de
false
. Las especializaciones estándar de
std::numpunct
devuelven
"false"
y
L
"false"
.
Ejemplo
Ejecutar este código
#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'; }
Salida:
Default locale, boolalpha true: true boolalpha false: false Locale with modified numpunct, boolalpha true: t boolalpha false: f