I am holding hex values in unsigned integers size_t
and would like to convert them into wchar_t
to hold in a data-structure and, optionally print to std::cout
as it's UTF-8 symbol/character when valid.
I've tried casting without much success: size_t h = 0x262E;
prints 9774
when doing a cast to wchar_t
for example.
Some minimal code:
#include <iostream>
#include <vector>
int main() {
std::setlocale( LC_ALL, "" );
auto v = std::vector<size_t>( 3, 0x262E ); // 3x peace symbols
v.at( 1 ) += 0x10; // now a moon symbol
for( auto &el : v )
std::cout << el << " ";
return 0;
}
Output: 9774 9790 9774
What I want: ☮ ☾ ☮
I can print the symbols using printf( "%lc ", (wchar_t) el );
. Is there a better "modern" C++ solution to this?
I need to be able to print anything in the range of 0000-27BF
UTF-8 on linux only.