【发布时间】:2023-09-20 02:05:01
【问题描述】:
用户 MGetz 在 this 帖子中告诉我使用 ncurses 在我的程序中呈现 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 甚至无法正确呈现,我明白了:
【问题讨论】: