How to display a unicode character correctly on terminal and write it to a file. I tried using wcout. But it is not displaying correctly.
I tried this code:-
#include <iostream>
using namespace std;
int main()
{
wchar_t orig = L'3333'; //3333 is the deciaml value of unicode character.
wcout <<orig<< endl;
return 0;
}
It should display അ But it is not having proper results..
What must be the reason. Is there any built in function in cpp to display unicode character correctly to console.
What i need exactly is that i have a unicode character in decimal or hexadecimal and i want to write it correctly to a file. So that when i open the file using any editor which can interpret unicode it should display the correct unicode.
First of all thanks to Disch for your help. Sorry for taking too much time to respond.
I solved it. I have rewritten the code as follows.
#include <iostream>
#include <locale>
using namespace std;
int main()
{
setlocale(LC_CTYPE,"");
wchar_t orig = 3333; //3333 is the deciaml value of unicode character.
wcout <<orig<< endl;
return 0;
}
Now i am getting the correct output. What i found is that setlocale function is necessary for setting program's current locale. Then only unicode can be printed. Also i replaced "wchar_t orig = L'3333'; " with " wchar_t orig = 3333; " .
So the decimal equivalent of the unicode(3333) will be stored in the wchar_t variable and wcout will print it.