An example of when you would want to imbue a new locale on a stream might be the case where a file has a header that requires a different code conversion facet. The following code imbues the JIS to UNICODE conversion facet from Chapter 19 onto a stream, reads a single line, then imbues the default locale to continue processing the file:
wstring header; wstring body; typedef basic_ifstream<wchar_t,JIS_char_traits> JIS_ifstream; JIS_fstream in("special.txt"); UnicodeJISConversion<wchar_t,char,JISstate_t> cvtfac; locale cvtloc(locale(),&cvtfac); in.rdbuf()->pubimbue(cvtloc); getline(in,header); in.rdbuf()->pubimbue(locale()); in >> body;
OEM Edition, OEM Edition, ©Copyright 1999, Rogue Wave Software, Inc.
Contact Rogue Wave about documentation or support issues.