4

Unlike English and Latin languages, Hebrew - in it's awesomeness, is written right to left. I wan't to get this message across to the computer realm.

I understand I have to use unicode/wchar for the actual string.

I understand I have to set the console to support unicode/wchar.

I understand I have to tell the console to use a supported font.

So I run this code:

#include "stdafx.h" // MS Visual Studio precompiled header file
#include <fcntl.h> // for _setmode
#include <io.h> // for _setmode
#include <windows.h> // for SetCurrentConsoleFontEx
int main()
{
    // use unicode/wchar as the actual string.
    wchar_t *hebrewString = L"עברית";

    // set the console to support unicode/wchar. 
    _setmode(_fileno(stdout), _O_U16TEXT);

    // tell the console to use a supported font.
    CONSOLE_FONT_INFOEX info = { 0 };
    info.cbSize = sizeof(info);
    info.dwFontSize.Y = 20;
    wcscpy_s(info.FaceName, L"Courier New");
    SetCurrentConsoleFontEx(GetStdHandle(STD_OUTPUT_HANDLE), NULL,  &info);

    // print
    wprintf(L"%s", hebrewString);

    // wait for input, so that console won't disappear immediately
    getchar();

    // return
    return 0;
}

This isn't bad, but the actual print is in reverse: enter image description here

Is there a way to properly configure it so that it will print in the right order, or do I have to manually flip the string before passing it to the console?

Ðаn
  • 10,934
  • 11
  • 59
  • 95
Maverick Meerkat
  • 5,737
  • 3
  • 47
  • 66
  • May be you could write your own stream which does reverse during newline or flush? You could store intermediate in `std::wstringstream`. Though performance won't be great. Other choice would be some platform specific code. – Incomputable May 18 '17 at 15:55
  • Please update the dead link. – Shibli May 18 '17 at 15:58
  • @Shibli, I don't see any link. – Incomputable May 18 '17 at 16:00
  • @Incomputable Right of *This isn't bad, but the actual print is in reverse:* – Shibli May 18 '17 at 16:01
  • I think you need to use a editor which support Hebrew so it would look like the same :P. Or you can use *user defined literals* to declare these string. Or create your own class. – apple apple May 18 '17 at 16:04
  • checkout `SetConsoleTextAttribute` with `COMMON_LVB_TRAILING_BYTE` attribute. Doc links [ [1](https://msdn.microsoft.com/en-us/library/windows/desktop/ms686047(v=vs.85).aspx), [2](https://msdn.microsoft.com/en-us/library/windows/desktop/ms686047(v=vs.85).aspx)]. User defined literals seem to be easier, but they are useless when multiple strings are needed on one line. – Incomputable May 18 '17 at 16:05
  • 3
    Already covered pretty well in [this existing answer](http://stackoverflow.com/a/21753872/17034) about the neighbors. – Hans Passant May 18 '17 at 16:20
  • @HansPassant LOL - thanks. I will for now use a reverse function. Until something better comes along. – Maverick Meerkat May 18 '17 at 16:27
  • @HansPassant now I read this in your link, from MSDN: "Console applications do not include text support for bi-directional languages. This is a consequence of how Windows works with console applications." guess there won't be anything better. – Maverick Meerkat May 18 '17 at 16:29

0 Answers0