I want to display an Arabic message mixed with Chinese using wcout.
The following code is OK:
#include <iostream>
using namespace std;
int main()
{
wcout.imbue(locale("chs"));
wcout << L"中文"; // OK
}
However, the following code doesn't work:
#include <iostream>
using namespace std;
int main()
{
wcout.imbue(locale(/* What to place here ??? */));
wcout << L"أَبْجَدِيَّة عَرَبِيَّة中文"; // Output nothing. VC++ 2012 on Win7 x64
// Why does the main advantage of unicode not apply here?
}
I think the concept of code pages should be deprecated after the adoption of unicode.
Q1. What's the mechanism of wout's displaying such a text?
Q2. Why does Windows, as a unicode-based OS, not support outputting unicode characters in its console window?
chcp 65001
), usage of correct fonts and without the problems which is specific with the usage some C++ libraries. – Teheran_setmode(_fileno(stdout), _O_WTEXT); std::wcout << L"أَبْجَدِيَّة عَرَبِيَّة中文Русский" << std::endl;
for example, but callchcp 65001
in the console before starting of your application. Then start it with option>%temp%\t.txt
to redirect the results in file and open>%temp%\t.txt
file in Notepad. You will see the text "أَبْجَدِيَّة عَرَبِيَّة中文Русский" correctly. – Teheran_O_U16TEXT
,_O_U8TEXT
or_O_WTEXT
is really enough to enable Unicode mode in the console application. To be able to see the results one have to use UNICODE code page (executechcp 65001
in the cmd). The last requirement is to use the Font in the console which can display the results. The last requirement is the most complex for common computer, so the only safe way will be piping the results to the file which really helpful only in seldom scenarios. – Teheran