//当用户输入密码时用*表示。但如果他输错的时候。用Delete键删除。在屏幕上也能看到“删除后少一个*的效果”
/* getch():
所在头文件:conio.h
函数用途:从控制台读取一个字符,但不显示在屏幕上
函数原型:int getch(void)
返回值:读取的字符
例如:
char ch;或int ch;
getch();或ch=getch();
用getch();会等待你按下任意键,再继续执行下面的语句;
用ch=getch();会等待你按下任意键之后,把该键字符所对应的ASCII码赋给ch,再执行下面的语句。
易错点:所在头文件是conio.h。而不是stdio.h。
C++中退格符 '/b'的具体作用效果
用个普通程序演示下用这个字符的输出结果与不用的区别。
#include<iostream.h>
int main()
{cout << "abc" <<"vf";//输出abcvf}
#include<iostream.h>
#include<conio.h>
int main()
{cout << "abc" << '/b' << "vf";//输出abvf}*/
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int i=0;
char a[8];
cout<<"请输入密码(密码长度不超过8位):"<<endl;
while(1)
{
a[i]=getch();
if(a[i]=='/b')//important,,e
{
cout<<'/b';
putch(' ');
cout<<'/b';
i--;
continue;
}
if(a[i]==13) //13为inter键
{
a[i]='/0';
break;
}
putch('*');
i++;
}
cout<<endl;
cout<<a;
system("pause");
return 0;
}