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

标签 c++ c++14 ncurses extended-ascii widechar

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

#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.

关于c++ - 使用 Ncurses (C++) 时不打印宽字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48466519/

相关文章:

c++ - 如何使用 TreeView_SetItem 改变 lParam?

performance - 分配但不构造大型 C++ 对象数组

c++ - 递归可变参数函数模板的返回类型的decltype

Ncurses 属性 A_DIM 无效

c++ - boost::asio::ip::tcp::socket 中的 async_read_some() 是如何工作的?

c++ - 通过 using 继承构造函数,但使其越线

c++ - 我可以像这样使用条件运算符吗?

c++ - __builtin_ctz(0) 或 __builtin_clz(0) 的未定义程度如何?

macos - happygrep-dyld : Library not loaded:/usr/local/opt/ncurses/lib/libncursesw. 5.dylib

c - 通过 ncurses 的引用行为传递