How to display L "أبجدي َّ ة عربي َّ ة 中文" using wcout?

I want to display an Arabic message mixed with Chinese using wcout.

The following code is in order:

#include <iostream> using namespace std; int main() { wcout.imbue(locale("chs")); wcout << L"中文"; // OK } 

However, the following code does not 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 obsolete after accepting unicode.

Q1. What wout mechanism displays such text?

Q2. Why doesn't Windows, like Unicode-based OS, support Unicode output in the console window?

+8
c ++ io windows-7 unicode
source share
4 answers

CRT will process all output as ANSI by default. You can change this with this line at the beginning of your program.

 _setmode(_fileno(stdout), _O_WTEXT); 

Good link @ http://www.siao2.com/2008/03/18/8306597.aspx

For reference purposes, bidirectional language support is limited in most command prompts, and as far as I understand, this limitation causes this problem. Why this is not supported / is not something that I cannot answer.

+7
source share

I just read this article

"To the summary ...

If you are using Visual C ++, you cannot use UTF-8 to print text in std :: cout.

If you still want to, please read this amazingly long article on how to make wcout and cout work, but it really doesn’t provide a simple solution - finally, to redefine stream buffers ... " http: //alfps.wordpress .com / 2011/12/08 / unicode-part-2-utf-8-stream-mode /

(from this blog http://blog.cppcms.com/post/105 )

+3
source share

You can try the following:

I assume that you could only display Chinese text. This means that you have Chinese font files.

Try it with arabic text. If you can render, that means you have an Arabic font in your system.

But when you mix it, Arabic + Chinese, then you need to make it select a font file that has both sets of glyphs. I think the default font file found by wcout does not have Arabic glyphs.

I assume you can get Arab Unicode boxes.

+1
source share
 #include <iostream> #include <io.h> #include <fcntl.h> int main() { _setmode(_fileno(stdout), _O_U16TEXT); // or _O_WTEXT std::wcout << L"أَبْجَدِيَّة عَرَبِيَّة‎中文" << std::endl; } 

http://www.cplusplus.com/forum/beginner/126557/

0
source share

All Articles