西游记狮子精是第几集:visual c++中,怎样使输入的字符串在DOS运行界面中以" * "号显示出来

来源:百度文库 编辑:高校问答 时间:2024/05/03 08:04:47
各位大哥大姐,有什么函数可以使键盘输入的字符串在DOS界面中以"*"号显示来出,类似于输入一个密码.

#include<iostream>
#include<string>
#include <conio.h>
using namespace std;
void main()
{
char ch;
string text;
cout<<"请输入明文:"<<endl;
ch=getch();
while( ch != 13 )
{
text=text+ch;
putchar('*');
ch = getch();
}
cout<<"\n你输入的密文是:\n"<<text<<endl;

}

运行结果是:

请输入明文:
******************************
你输入的密文是:
the result of 2 and 3 is not 8
Press any key to continue

#include "stdafx.h"
#include "conio.h"

int main(int argc, char* argv[])
{
char key;
......
key=getch();
while(key!=13)
{
putchar('*');
key=getch();
...... //这里可以设置变量保存用户的按键
}
......
return 0;
}