C++ examples for Internationalization:Money
Using moneypunct and numpunct to obtain the punctuation and grouping rules for the United States:
#include <iostream> #include <locale> using namespace std; int main()//w ww.ja v a 2s . c o m { // Create a locale for US English. locale usloc("English_US"); // Set the locale of cout to US English. cout.imbue(usloc); // Get a moneypunct facet for cout. const moneypunct<char> &us_monpunct = use_facet<moneypunct<char> >(cout.getloc()); cout << "Monetary punctuation for US:\n"; cout << " Currency symbol: " << us_monpunct.curr_symbol() << endl; cout << " Decimal point: " << us_monpunct.decimal_point() << endl; cout << " Thousands separator: " << us_monpunct.thousands_sep() << endl; cout << " Fraction digits: " << us_monpunct.frac_digits() << endl; cout << " Number of grouping rules: " << us_monpunct.grouping().size() << endl; for(unsigned i=0; i < us_monpunct.grouping().size(); ++i) cout << " Size of group " << i << ": " << (int)us_monpunct.grouping()[0] << endl; cout << endl; // Get a numpunct facet for cout. const numpunct<char> &us_numpunct = use_facet<numpunct<char> >(cout.getloc()); cout << "Numeric punctuation for US:\n"; cout << " Decimal point: " << us_monpunct.decimal_point() << endl; cout << " Thousands separator: " << us_monpunct.thousands_sep() << endl; cout << " Number of grouping rules: " << us_monpunct.grouping().size() << endl; for(unsigned i=0; i < us_monpunct.grouping().size(); ++i) cout << " Size of group " << i << ": " << (int)us_monpunct.grouping()[0] << endl; return 0; }