使用 addch 获得意想不到的字符

Getting an unexpected character with addch

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

我试过将 TCHAR 转换为 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 (Unreal Engine 4 中使用的类型),我检查了 FString 长度并且它是正确的,而结果是'出乎我的意料。

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

addch 需要一个 chtype 参数,它包含一个 8 位字符(如果你碰巧传递给它一个 NUL , 它将显示为 ^@).

wchar_t 包含超过 8 位的字符。使用 addwstr 表示 that.