Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
locale.cpp
Go to the documentation of this file.
1
29#include <rw/_defs.h>
30
31#if defined (_AIX) && defined (__IBMCPP__) && !defined (_RWSTD_NO_IMPLICIT_INCLUSION)
32# define _RWSTD_NO_IMPLICIT_INCLUSION
33#endif
34
35#include <algorithm> // for copy, sort
36#include <iostream> // for cout
37#include <iterator> // for ostream_iterator
38#include <string> // for string
39#include <vector> // for vector
40
41#include <codecvte.h>
42#include <examples.h>
43
44int main ()
45{
46 std::locale loc; // Default locale
47
48 // Construct new locale using default locale plus
49 // user defined codecvt facet
50 // This facet converts from ISO Latin
51 // Alphabet No. 1 (ISO 8859-1) to
52 // U.S. ASCII code page 437
53 // This facet replaces the default for
54 // codecvt<char,char,mbstate_t>
55 std::locale my_loc (loc, new ex_codecvt);
56
57 // imbue modified locale onto cout
58 std::locale old = std::cout.imbue (my_loc);
59 std::cout << "A \x93 jolly time was had by all" << std::endl;
60
61 std::cout.imbue (old);
62 std::cout << "A jolly time was had by all" << std::endl;
63
64 // Create a vector of strings
65 std::vector<std::string, std::allocator<std::string> > v;
66 v.insert (v.begin(), "antelope");
67 v.insert (v.begin(), "bison");
68 v.insert (v.begin(), "elk");
69
70 typedef std::ostream_iterator<std::string, char, std::char_traits<char> >
71 Iter;
72
73 std::copy (v.begin (), v.end (), Iter (std::cout, " "));
74 std::cout << std::endl;
75
76 // Sort the strings using the locale as a comparitor
77 std::sort (v.begin (), v.end (), loc);
78
79 std::copy (v.begin (), v.end (), Iter (std::cout," "));
80
81 std::cout << std::endl;
82
83 return 0;
84}
#define v
Definition 17.names.cpp:138
#define loc
Definition 17.names.cpp:492
#define old
Definition 17.names.cpp:509
std::ostream_iterator< int, char, std::char_traits< char > > Iter
Definition alg7.cpp:64
int main()
Definition locale.cpp:44