c++ - In C++11, how to print a character given its Unicode code? -
i sure dumb question, there straightforward way print unicode character in c++ given hex code? instance: know code ❤ 0x2764. there way can use code print (either via printf or on stream)?
for record, can print character writing:
cout << "\u2764" << endl;
but requires knowing value @ compile time rather using variable.
thanks
from comment see you're on os x, uses utf-8 , has sufficiently complete implementation of c++11 library (libc++) following work.
#include <codecvt> // wstring_convert, codecvt_utf8 #include <iostream> // cout int main() { std::wstring_convert<std::codecvt_utf8<char32_t>, char32_t> convert; std::cout << convert.to_bytes(static_cast<char32_t>(0x2764)) << '\n'; }
this depends on console working utf-8, os x's does.
Comments
Post a Comment