名稱空間
變體
操作

std::numpunct<CharT>::truename, do_truename, falsename, do_falsename

來自 cppreference.com
< cpp‎ | locale‎ | numpunct
 
 
 
 
 
定義於標頭檔案 <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_truenamedo_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