我被告知使用ncurses
在this帖子中由用户MGetz在我的程序中呈现unicode级别。所以,我已经更新了我的代码以使用ncurses
,但它在不同的终端中仍然呈现不同的方式。我使用g++ file.cpp -o file -std=c++11 -lncursesw
编译了我的代码。说到我的代码,就在这里。
#include <iostream>
#include <string>
#include <ncurses.h>
#include <locale.h>
using namespace std;
void PrintLevel();
string lvl[9][11] {
{"\u250f", "\u2501", "\u2501", "\u2501", "\u2501", "\u2501", "\u2501", "\u2501", "\u2501", "\u2501", "\u2513"},
{"\u2503", "\u0020", "\u0020", "\u0020", "\u0020", "\u0020", "\u0020", "\u0020", "\u0020", "\u0020", "\u2503"},
{"\u2503", "\u0020", "\u0020", "\u0020", "\u0020", "\u0020", "\u0020", "\u0020", "\u0020", "\u0020", "\u2503"},
{"\u2503", "\u0020", "\u0020", "\u0020", "\u0020", "\u0020", "\u0020", "\u0020", "\u0020", "\u0020", "\u2503"},
{"\u2503", "\u0020", "\u0020", "\u0020", "\u0020", "\u0020", "\u0020", "\u0020", "\u0020", "\u0020", "\u2503"},
{"\u2503", "\u0020", "\u0020", "\u0020", "\u0020", "\u0020", "\u0020", "\u0020", "\u0020", "\u0020", "\u2503"},
{"\u2503", "\u0020", "\u0020", "\u0020", "\u0020", "\u0020", "\u0020", "\u0020", "\u0020", "\u0020", "\u2503"},
{"\u2503", "\u0020", "\u0020", "\u0020", "\u0020", "\u0020", "\u0020", "\u0020", "\u0020", "\u0020", "\u2503"},
{"\u2517", "\u2501", "\u2501", "\u2501", "\u2501", "\u2501", "\u2501", "\u2501", "\u2501", "\u2501", "\u251B"}
};
int main() {
setlocale(LC_ALL, "");
initscr();
PrintLevel();
getch();
endwin();
}
void PrintLevel() {
for(int i = 0; i<9; i++) {
for(int j = 0; j<11; j++) {
printw(lvl[i][j].c_str());
if(j == 10) {
printw("\n");
}
}
}
refresh();
}
哦,仅供参考,我正在使用Codenvy,因为我只能访问我的学校Chromebook。尝试在另一个类似Codenvy的服务Codeanywhere上,Unicode甚至无法正确呈现,我明白了:
答案 0 :(得分:0)
副手:
setlocale
使用区域设置,但不要提及它们的内容(LC_ALL
等,如 locale
所示命令)和如果您同时使用错误的区域设置并使用 ncurses 进行关联,则可能会显示该图片。