我需要从标准输入读取密码,并且不想std::cin回显用户输入的字符...
如何禁用std :: cin的回声?
这是我目前使用的代码:
string passwd;
cout << "Enter the password: ";
getline( cin, passwd );
Run Code Online (Sandbox Code Playgroud)
我正在寻找一种与操作系统无关的方法来做到这一点. 这里有一些方法可以在Windows和*nix中执行此操作.
我怎么能这样做,我可以在C++中显示星号(*)而不是纯文本的密码.
我要求输入密码,它在屏幕上显示通过.
如何将它们转换为星号(*),以便用户在输入时无法看到密码.
这就是我目前所拥有的
char pass[10]={"test"};
char pass1[10];
textmode(C40);
label:
gotoxy(10,10);
textcolor(3);
cprintf("Enter password :: ");
textcolor(15);
gets(pass1);
gotoxy(10,11);
delay(3000);
if(!(strcmp(pass,pass1)==0))
{
gotoxy(20,19);
textcolor(5);
cprintf("Invalid password");
getch();
clrscr();
goto label;
}
Run Code Online (Sandbox Code Playgroud)
谢谢