Namespaces
Variants
Views
Actions

std::numpunct::truename, std::numpunct::do_truename, std::numpunct::falsename, std::numpunct::do_falsename

From cppreference.com
< cpp‎ | locale‎ | numpunct
Revision as of 06:23, 23 April 2013 by P12 (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Template:ddcl list begin <tr class="t-dsc-header">

<td>
Defined in header <locale>
</td>

<td></td> <td></td> <tr class="t-dcl ">

<td >
public:
string_type truename() const;
</td>

<td > (1) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td >
public:
string_type falsename() const;
</td>

<td > (2) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td >
protected:
virtual string_type do_truename() const;
</td>

<td > (3) </td> <td class="t-dcl-nopad"> </td> </tr> <tr class="t-dcl ">

<td >
protected:
virtual string_type do_falsename() const;
</td>

<td > (4) </td> <td class="t-dcl-nopad"> </td> </tr> Template:ddcl list end

1-2) Public member function, calls the member function do_truename and do_falsename of the most derived class respectively.

3) Returns the string to be used as the representation of the boolean value true.

Return value

1-2) The object of type string_type to use as the representation of true. The standard specializations of std::numpunct return "true" and L"true".
3-4) The object of type string_type to use as the representation of false. The standard specializations of std::numpunct return "false" and L"false".

Example

#include <iostream>
#include <locale>
#include <iomanip>
 
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;
    std::cout << "default locale: " << true << true << false << false << '\n';
    std::cout.imbue(std::locale(std::cout.getloc(), new custom_tf));
    std::cout << "locale with modified numpunct: " 
              << true << true << false << false << '\n';
}

Output:

default locale: truetruefalsefalse
locale with modified numpunct: ttff