2012-10-18 75 views
2

我需要一个DLL,供用户输入密码而不在屏幕上回显。 于是我就用_getch()用于获取字符与这样的无回声区,_getch()不能在Windows Server 2012上工作

 //get character with no echo 
     ch = _getch(); 

和编译代码使用Microsoft VS2005。
它可以在windows server 2003/2008上运行,但在新的windows server 2012上,它会将字符回显到屏幕上。
我的问题是为什么_getch()只在Windows Server 2012上回显字符?以及如何解决它?

+0

'ReadConsoleInput'? – Mehrdad

+0

最后我发现'_getch()'效果很好,问题是我使用'fgetpos'和'fsetpos'来检查'stdin'中是否有任何流。我用'fseek(stdin,0,SEEK_END)'替换它们,它现在在2012年的效果很好。 – jmuok

+0

您不应该使用'_isatty'来检查流是否是'stdin'吗? – Mehrdad

回答

0

使用cin.get()代替getch()。

+0

这个问题被标记为c和C++; 'cin.get()'在C. –

+0

中不可用,但它在C++中!不是吗? –

+0

是的,但(a)如果OP将问题标记为c和C++,他可能正在寻找一种能够在两种语言中工作的解决方案,并且(b)'cin.get()'不会关闭回显。 –

相关问题