【发布时间】:2012-10-18 04:23:07
【问题描述】:
我需要一个 DLL,以便用户可以键入密码而不是在屏幕上回显。
所以我使用_getch() 来获取没有回声的字符,
//get character with no echo
ch = _getch();
并使用microsoft vs2005编译代码。
它适用于 windows server 2003/2008,但在新的 windows server 2012 上,它会将字符回显到屏幕上。
我的问题是为什么 _getch() 回显字符仅在 Windows Server 2012 上?以及如何解决?
【问题讨论】:
-
最后我发现
_getch()工作得很好,问题是我使用fgetpos和fsetpos来检查stdin中是否有任何流。我将它们替换为fseek(stdin,0,SEEK_END),目前它在 2012 年运行良好。 -
您不应该使用
_isatty来检查流是否为stdin? -
感谢您的建议。我改用
_isatty像这样int re = _isatty(_fileno(stdin));它的作品。_isatty比fseek更好吗?(我只在 windows 操作系统上使用)非常感谢。 -
是的,
_isatty是“正确”的做法。我不确定您所说的“为什么”是什么意思……我想我从来没有读过任何应该使用fseek来确定输入类型的地方。
标签: c++ c getch windows-server-2012