tags:

views:

284

answers:

2

How to write unicode character farsi in c++ in ms-dos?

cout<<"Helo world"<<"سلام جهان";

+3  A: 

You need to convert the string to proper codepage. MS-DOS codepages are named like CP437, with CP followed by three digits. Notice that normally only less than 256 different characters may be displayed and thus many Unicode characters just cannot be shown in text mode.

Tronic
CP708 is the Arabic code page in MS-DOS. See http://msdn.microsoft.com/en-us/library/cc195051.aspx for the full list from Microsoft.
David
+3  A: 
#include <iostream>
#include <locale>
#include <string>

int main()
{
      using namespace std;
      wstring wcs = L"中文";
      locale old = wcout.imbue(locale("") ); // "" is environment's default locale
      wcout<<wcs<<endl;
      wcout.imbue(old );                     // restore old locale
}
OwnWaterloo
Doesn't answer the question: this writes wholly different characters :P
Thomas
@Thomas: But unless you are completely brain dead (which I hope is not true for all programmers). The ability to change the above program to print out different characters will be (how should I put it) "A braid dead cut and paste". The whole point is to set the correct local (since the default is the "C" locale which is usualy not very good at anything but English).
Martin York
Don't forget to use a font that contains the letters of the desired langauge. Also, Farsi like Arabic is RTL, some letters are connected other are not and what not. Good luck trying to "fix" the stupid win console to do what you want ;)
AraK
@Martin:are you claiming that the "C" locale *is* good at English? If so, I'd beg leave to disagree...
Jerry Coffin
@Jerry: No. My sentence is very explicit and that is not what it says.
Martin York
I run this code but not show anything!!!
S.Mehdi