首页 > 解决方案 > 使用 addch 获得意想不到的角色

问题描述

我将 ncurses 与 一起使用noecho(),并且我正在尝试从具有函数的TCHAR(或char16_t)数组中打印字符串。addch()

我尝试将 myTCHAR转换为 int,但结果相同。

这是我正在使用的代码:

coords hCursorPosition( GetCursorPosition() );
        if ( hCursorPosition.X == 0 ) return;
        coords nCursorPosition(hCursorPosition.Y, 0);
        SetCursorPosition(nCursorPosition);
        clrtoeol();
        if (!m_sInput.IsEmpty())
        {
            for (auto CharIt(m_sInput.CreateConstIterator()); CharIt; CharIt++)
            {
                const TCHAR Char = *CharIt;
                int intChar = static_cast<int>(Char);
                addch(intChar);
                refresh();
            }
        }

m_sInput是一个FString(在虚幻引擎 4 中使用的类型),我检查了FString长度并且它是正确的,而结果不是我所期望的。

例如,如果m_sInput是“test”,我的输出将是“test^@”

标签: c++linuxncursesunreal-engine4

解决方案


addch expects a chtype parameter, which contains an 8-bit character (and if you happen to pass it a NUL, it will show that as ^@).

wchar_t holds more than an 8-bit character. Use addwstr for that.


推荐阅读