1

I'm trying to output Unicode that corresponds to an integer value entered by the user. This is being done on windows 10 in C++ by the way. Currently I can print Unicode with this code:

_setmode(_fileno(stdout), _O_U16TEXT);

wprintf(L"\u0006");'''

My question is, how do I attach the variable to the Unicode?

1 Answer 1

0

Something like this

wchar_t wstr[2] = { variable, L'\0' };
wprintf(L"%ls", wstr);

Alternatively, you can avoid the expense of wprintf with

wchar_t wstr[2] = { variable, L'\0' };
fputws(wstr, stdout);

In both cases variable is the integer variable you mentioned. You might want to check that is in range for a wchar_t and you might want to add a cast to suppress any compiler warning.

Sign up to request clarification or add additional context in comments.

11 Comments

I'm not sure what you don't understand. Are you not familar with null terminated strings, with printf style formatting, with array initialisation?
Never mind that, I was being stupid. It's just that its giving me errors when i try it.
OK, well I haven't tested anything, what errors are you getting?
Sorry still half asleep, it should be fixed now.
I've tested it now, it's working for me. I didn't know about _setmode(_fileno(stdout), _O_U16TEXT); so that's good to learn.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.