简体   繁体   中英

How to print special characters in c++ for mac using ncurses libarary

Now, I want to print special characters in c++ for mac(mojava, 10.14.4), but these characters are broken in my mac book.

I installed ncurses such as brew install ncurses and brew link ncurses . It can printw English such as Hello World , but special characters such as ████████╗███████╗████████╗██████╗ ██╗███████╗ is broken.

source code

setup

initscr();
clear();
noecho();
cbreak();
curs_set(0);

work

int startX = 0;
int startY = 0;

mvprintw(startY++, startX, "Hello World");
mvprintw(startY, startX, "████████╗███████╗████████╗██████╗ ██╗███████╗\n");

Result

Hello World
?~V~H?~V~H?~V~H?~V~H?~V~H?~V~H?~V~H?~V~H?~U~W?~V~H?~V~H?~V~H?~V~H?~V~H?~V~H?~V~H
?~U~W?~V~H?~V~H?~V~H?~V~H?~V~H?~V~H?~V~H?~V~H?~U~W?~V~H?~V~H?~V~H?~V~H?~V~H?~V~H
?~U~W ?~V~H?~V~H?~U~W?~V~H?~V~H?~V~H?~V~H?~V~H?~V~H?~V~H?~U~W

This seems to work for c++ with clang++ for mac(Mojave, 10.14.4). I think it is using the mac curses rather than the brew installed ncurses. It looks like it needs the locale set: setlocale(LC_ALL, ""); For me, this cleared the screen and displayed:

Hello World ████████╗███████╗████████╗██████╗ ██╗███████╗

Compile cmd:
clang++ -Wall -Wextra -Weverything -lncurses *.cpp -o prg

main.cpp code:

#include <curses.h>
#include <locale.h>

int main()
{
    setlocale(LC_ALL, "");
    initscr();                /* Start curses mode */
    clear();
    noecho();
    cbreak();
    curs_set(0);

    int startX = 0;
    int startY = 0;
    mvprintw(startY++, startX, "Hello World");
    mvprintw(startY, startX, "████████╗███████╗████████╗██████╗ ██╗███████╗\n");

    refresh();                /* Print it on the real screen */
    getch();                  /* Wait for user input */
    endwin();                 /* End curses mode */
    return 0;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM