Click here to Skip to main content
15,881,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm using C++ on windows and I'm trying create some code that will allow me to input and Unicode character code, then output that character to the console. I'm well aware of the issues associated with Unicode and the console, however that is not the problem I'm trying to fix.

What I have tried:

So far I have some code that will print out the character, if given the code before hand.
C++
int main()
{

    

    _setmode(_fileno(stdout), _O_WTEXT);
    
    wprintf(L"\u0004"); // A Unicode code should go in there as a variable.



    return 0;
}


I know how to output the character if I enter the code into L"\u(numeric code goes here)", what I'm looking for is a way to insert a variable code in there. I hope this makes sense.
Posted
Updated 25-Jul-20 7:10am
v3

This should work
C++
const wchar_t * wstring = L"some wide string";
wprintf( L"%s\n", wstring );
for a string. For a single character try this :
C++
wchar_t wideChar = 0x1234;
wprintf( L"hex: %04X  char: %c\n", wideChar, wideChar );
 
Share this answer
 
v2
variable isn't a unicode character - it's string of 4 characters.
You would need to convert that to a wide character before you output it, and that means you need to think about what that string represents: a number, a value, a hex value, or what?

At the moment, you question is pretty much meaningless - you need to stop and think about what you are trying to achieve, instead of just diving into code.
 
Share this answer
 
Comments
Lachy 314 25-Jul-20 4:04am    
Sorry, My question was not clear enough. I know how to output the character if I enter the code into L"\u(numeric code goes here)", what I'm looking for is a way to insert a variable code in there. I hope this makes more sense.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900