Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
moneypunct.cpp
Go to the documentation of this file.
1
29#include <climits> // for CHAR_MAX
30#include <clocale> // for lconv, localeconv()
31#include <iostream> // for cout, endl
32#include <locale> // for locale
33
34#include <examples.h>
35
36
37int main ()
38{
39 // Get a moneypunct facet from the classic "C" locale
40 const std::moneypunct<char, false> &mp =
41 std::use_facet<std::moneypunct<char, false> >(std::locale::classic ());
42
43 const std::lconv* const lc = std::localeconv ();
44
45 // Expected output:
46 // Punctuator C++ C99
47 // Decimal point = '.' "."
48 // Thousands separator = ',' ""
49 // Currency symbol = "" ""
50 // Negative Sign = "" ""
51 // Positive Sign = "" ""
52 // Digits after decimal = 0 CHAR_MAX
53
54 std::cout << "Punctuator C++ C99\n";
55
56 std::cout << "Decimal point = '"
57 << mp.decimal_point () << "' \""
58 << lc->decimal_point << '"';
59
60 std::cout << "\nThousands separator = '"
61 << mp.thousands_sep () << "' \""
62 << lc->thousands_sep << '"';
63
64 std::cout << "\nCurrency symbol = \""
65 << mp.curr_symbol () << "\" \""
66 << lc->currency_symbol << '"';
67
68 std::cout << "\nNegative Sign = \""
69 << mp.negative_sign () << "\" \""
70 << lc->negative_sign << '"';
71
72 std::cout << "\nPositive Sign = \""
73 << mp.positive_sign () << "\" \""
74 << lc->positive_sign << '"';
75
76 std::cout << "\nDigits after decimal = "
77 << mp.frac_digits () << " ";
78
79 // since the value of CHAR_MAX depends on the signedness of char,
80 // if lc->frac_digits equals CHAR_MAX print the string "CHAR_MAX"
81 // to maintain the same output across all architectures, otherwise
82 // print the actual value
83
84 if (CHAR_MAX == lc->frac_digits)
85 std::cout << "CHAR_MAX";
86 else {
87 // this block should not be entered in a conforming environment
88 // since, according to 7.11, p2 of C99, frac_digits is required
89 // to be equal to CHAR_MAX in the "C" locale
90
91 // cast lconv::frac_digits from char to int to print out
92 // the numeric value of the member
93 std::cout << int (lc->frac_digits)
94 << " (libc bug: expected CHAR_MAX, i.e., "
95 << unsigned ((unsigned char)CHAR_MAX)
96 << ")";
97 }
98
99 std::cout << std::endl;
100
101 return 0;
102}
#define CHAR_MAX
Definition limits.h:44
int main()