How to print a unicode character on terminal correctly and write it to a file?

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.

On Ubuntu, with various terminals, I've had success outputting UTF-8 characters simply by using cout (not wcout):

 
cout << "അ";


The above works as expected on my machine, provided I make sure the source file is UTF-8 encoded.

Sadly, there is no guarantee this will work on all computers. I really wish the standard lib did a better job of conforming to 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.


Thanks Disch for your help.
Topic archived. No new replies allowed.