Converting from a Local Encoding to UTF-16
To provide a convenient method for translation between character encodings, RWUString works directly with character-encoding converters in the Internationalization Module.
For example, if you want to write out to UTF-16 a string encoded in the Japanese Shift-JIS, you would use the following.
#include "rw/i18n/RWUToUnicodeConverter.h" // 1
RWCString myString;
 
// Initialize myString with characters encoded in Shift-JIS
RWUToUnicodeConverter fromShiftJis("Shift-JIS"); // 2
RWByteOutputStream& tmpBStream =
RWByteToStreambufOutputStreamImp::make(cout.rdbuf());
RWDataOutputStream tmpDStream =
RWNativeDataToByteOutputStreamImp::make(tmpBStream);
RWObjectOutputStream out =
RWCompactObjectOutputStreamImp::make(tmpDStream); // 3
 
out << RWUString(myString, fromShiftJis); // 4
//1 Include the header file for the “to Unicode” converter class.
//2 Create a converter for converting from Shift-JIS to UTF-16.
//3 Create the compact object output stream.
//4 Using the constructor that takes a second “converter” parameter, construct an RWUString from the RWCString containing characters encoded in Shift-JIS. The Shift-JIS characters will be converted to UTF-16 as part of the construction. Then shift out the RWUString.