使用 Ncurses (C++) 时不打印宽字符

Wide Characters not printing while using Ncurses (C++)

下面的代码无法打印宽字符:

#include <ncurses.h>

using namespace std;

int main(void){
  initscr();
  printw("█");
  getch();
  endwin();
}

虽然所有库都已正确安装,但此代码似乎在某些计算机上有效,而在其他计算机上无效。 (终端可以显示扩展字符!)

我编译这个使用:

g++ -std=c++14 widechartest.cpp -o widechar -lncursesw

有人可以告诉我问题出在哪里吗? 谢谢 8)

您没有初始化语言环境。 manual page 指出了这一点:

The library uses the locale which the calling program has initialized. That is normally done with setlocale:

setlocale(LC_ALL, "");

If the locale is not initialized, the library assumes that characters are printable as in ISO-8859-1, to work with certain legacy programs. You should initialize the locale and not rely on specific details of the library when the locale has not been setup.