Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/126.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用addch获取意外字符_C++_Linux_Ncurses_Unreal Engine4 - Fatal编程技术网

C++ 使用addch获取意外字符

C++ 使用addch获取意外字符,c++,linux,ncurses,unreal-engine4,C++,Linux,Ncurses,Unreal Engine4,我正在使用带有noecho()的ncurses,并尝试使用addch()函数从TCHAR(或char16\u t)数组打印字符串 我尝试将我的TCHAR强制转换为int,但结果相同 这是我正在使用的代码: 协调hCursorPosition(GetCursorPosition()); 如果(hCursorPosition.X==0)返回; 坐标n坐标(hCursorPosition.Y,0); SetCursorPosition(nCursorPosition); clrteool(); 如果(

我正在使用带有
noecho()
的ncurses,并尝试使用
addch()
函数从
TCHAR
(或
char16\u t
)数组打印字符串

我尝试将我的
TCHAR
强制转换为int,但结果相同

这是我正在使用的代码:

协调hCursorPosition(GetCursorPosition()); 如果(hCursorPosition.X==0)返回; 坐标n坐标(hCursorPosition.Y,0); SetCursorPosition(nCursorPosition); clrteool(); 如果(!m_sInput.IsEmpty()) { for(自动CharIt(m_sInput.createconditerator());CharIt;CharIt++) { const TCHAR Char=*CharIt; int intChar=静态_cast(Char); addch(intChar); 刷新(); } }
m_sInput
是一个
FString
(在虚幻引擎4中使用的类型),我已经检查了
FString
长度,它是正确的,但结果不是我所期望的

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

需要一个
chtype
参数,该参数包含一个8位字符(如果您碰巧向它传递了
NUL
,它将显示为
^


wchar\u t
包含的字符多于8位。使用它。

您在Windows上,对吗?这可能会有帮助:谢谢你的回答!无论如何,我犯了一个错误:TCHAR是一个char16_t,所以我在使用addwstr时遇到了这个编译错误:错误:无法用一个类型为“const TCHAR”(又名“const char16_t”)的左值初始化一个类型为“const char*”的参数,解决了用以下内容替换代码的问题:
if(!m_sInput.IsEmpty()){addstr(TCHAR TO_TO_ANSI(*m_sInput));refresh()}
@Scienziatogm
TCHAR
是您告诉编译器的大小。它旨在将代码从旧的基于DOS的操作系统移植到基于Windows NT的操作系统。一个20多年前的问题解决方案。现在,如果你避免使用
TCHAR
来防止像这样有趣的意外,通常是最好的。@user4581301
TCHAR
是由Unreal引擎定义的,以支持广泛的平台,从实践中我可以看到,它总是被定义为
wchar\u t
@Rotem是的,但在这种情况下,它被定义为常量字符