如何使用Ncurses打印(☞)? [英] How can I print (☞゚ヮ゚)☞ with Ncurses?

查看:121
本文介绍了如何使用Ncurses打印(☞)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Ubuntu中使用C ++在Ncurses库中打印(☞).

I would like to print (☞゚ヮ゚)☞ with the Ncurses library using C++ in Ubuntu.

首先,您可以通过以下简单操作来实现此目的:

First of all, you can do this by simply having:

std::cout << "(☞゚ヮ゚)☞" << std::endl;

它很好用.

但是,当使用Ncurses打印时,我认为您需要使用printw(char[]).在这种情况下,我会尝试这样的事情:

However, when printing using Ncurses, I think that you need to use printw(char[]). In which case, I try something like this:

std::string str = "(☞゚ヮ゚)☞";   // String
initscr();                     // Start curses mode
printw(str.c_str());           // Print
getch();                       // Wait for input
endwin();                      // Exit curses mode

但是它输出:

( 〜X〜^ 〜.~~C 〜).〜X〜^

我曾经以为可能是c_str()的错,但是当我使用std::cout进行操作时,它也可以正常工作.

I had thought that maybe it was c_str()'s fault, but when I do it with std::cout it works just fine too.

如何使用Ncurses打印该文本?为什么它与std::cout一起使用而不与Ncurses的printw(char[])一起使用?

How can I print that text with Ncurses? Why does it work with std::cout and not with Ncurses' printw(char[])?

我使用

g++ Main.cpp -lncurses

在64位计算机上. Ubuntu(也是64位)正在以OSX为主机的VirtualBox中运行.

In a 64-bit machine. Ubuntu (64 bits too) is running in VirtualBox with OSX as host.

更新:

我已被重定向到 https://stackoverflow.com/a/9927113/555690 .那里的解决方案似乎无法解决我的问题-相反,这是现在的样子:

I've been redirected to https://stackoverflow.com/a/9927113/555690. The solution there doesn't seem to fix my problem - instead, this is how it looks now:

(M-b〜X〜^ M-oM->〜 M-c〜CM-.M-oM->〜)M-b〜X〜^

(M-b~X~^M-oM->~M-c~CM-.M-oM->~)M-b~X~^

推荐答案

我想我会将其发布为答案.因此,Ubuntu在默认情况下显然没有附带Unicode支持版本.因此,您首先需要使用

I guess I'll post this as the answer. So, Ubuntu does apparently not by default ship with the Unicode supporting version. So you first need to install it with

sudo apt-get install libncursesw5-dev

然后您可以编译它

#include <iostream>
#include <string>
#include "locale.h"
#include "ncursesw/ncurses.h"
using namespace std;

int main()
{
    setlocale(LC_ALL, "");
    std::string str = "(☞゚ヮ゚)☞";   // String
    initscr();                     // Start curses mode
    printw(str.c_str());           // Print
    getch();                       // Wait for input
    endwin();  
    return 0;
}

它会顺利运行.

注意#include "ncursesw/ncurses.h"

这篇关于如何使用Ncurses打印(☞)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆