Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1833416
  • 博文数量: 283
  • 博客积分: 10141
  • 博客等级: 上将
  • 技术积分: 2931
  • 用 户 组: 普通用户
  • 注册时间: 2005-12-21 14:33
文章分类

全部博文(283)

文章存档

2013年(2)

2012年(2)

2011年(17)

2010年(36)

2009年(17)

2008年(18)

2007年(66)

2006年(105)

2005年(20)

分类: C/C++

2005-12-24 09:58:17

先说C的方法,这个方法是被称为“终极解决方法”的 :)

#include
#include

static struct termios stored_settings;
void echo_off(void)
{
    struct termios new_settings;
    tcgetattr(0,&stored_settings);
    new_settings = stored_settings;
    new_settings.c_lflag &= (~ECHO);
    tcsetattr(0,TCSANOW,&new_settings);
    return;
}

void echo_on(void)
{
    tcsetattr(0,TCSANOW,&stored_settings);
    return;
}

嗯,其他方法也有吧,比如用#include 中的getch之类的函数自己写一个...

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Perl的方法也不少,嗯。

`stty -echo`;
$passwd=;
`stty echo`;

------------------------------------------------------------

也可以安装Term::ReadKey模块,然后这样:
use Term::Readkey;
ReadMode(''''noecho'''');
$password = ReadLine(0);

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

哪位路过的有好用的方法也写在留言里show一下吧 ;-)

阅读(1748) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~