Output Stream Example

To write out a string encoded in Shift-JIS, use following code.

 

#include "rw/i18n/RWUToUnicodeConverter.h" // 1

RWCString myString;

// Initialize myString with characters encoded in Shift-JIS

RWUToUnicodeConverter fromShiftJis("Shift-JIS"); // 2

RWObjectOutputStream out = RWXmlObjectOutputStreamImp::make(cout);// 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 XML output stream.

// 4   Construct an RWUString (using the constructor that takes a second “converter” parameter) from the RWCString containing characters encoded in Shift-JIS. The constructor will convert the Shift-JIS characters to UTF-16. Then shift out the RWUString. The inserter for the XML output stream will convert the UTF-16 characters in the RWUString to the UTF-8 required by XML.