#include #include #include using namespace std; int main() { char16_t pi{u'\u03C0'}; char32_t ducks{U'\U00013179'}; u16string phrase1{u"pi = "}; u32string phrase2{U"But ducks (\U00013177) are "}; u32string phrase3; cout << "\u03B1 to \u03A9 are easy as \U00013197." << endl; wstring_convert, char16_t> converter16; wstring_convert, char32_t> converter32; phrase1 = phrase1 + pi; string tmp = converter16.to_bytes(phrase1); cout << tmp << endl; cout << "The phrase is " << dec << phrase1.size() << " characters long." << endl; // caution here: // hex will put the stream in hex mode until changed! // So all output will be in hex until you change the stream back. // This is done with dec for(int i = 0; i < phrase1.size(); ++i) { cout << hex << static_cast(phrase1[i]) << " " ; } cout << endl << endl; phrase2 += ducks; tmp = converter32.to_bytes(phrase2); cout << tmp << endl; cout << "The phrase is " << dec << phrase2.size() << " characters long." << endl; for(int i = 0; i < phrase2.size(); ++i) { u32string singleChar = phrase2.substr(i,1); string eightBitSingleChar = converter32.to_bytes(singleChar); cout << "\t" << dec << i << " " << eightBitSingleChar << " " << hex << static_cast(phrase2[i]) << endl; } cout << endl << endl; return 0; }