密码屏蔽(不重复)

Password Masking(not duplicate)

编译器代码::块 操作系统(OS)-Windows

我写了一个非常简单的密码屏蔽程序,不像我构建的 internet.When 上的复杂程序和 运行 我的代码它显示 "Enter password" 但不允许我输入任何内容。

通过密码屏蔽我的意思是当我输入密码时它显示为 **** 就像在电子邮件中一样输入。(每个字符一个*)

#include <iostream>
#include <string>
#include <conio.h>

using namespace std;

int main()
{
    string pass;

    cout << "Enter password";

    for (int i=0; i<100; i++)
    {
        char ch = getch();

        if (ch == 13)
            break;

        if (ch == 8)
        {
            if (pass.size())
            {
                cout << "\b \b";
                pass.pop_back();
            }
        }
        else
        {
            cout << "*";
            pass += ch;
        }
    }

    cout <<  "pass = " << pass << '\n';
}

呃。我找到了有史以来最简单的解决方案。 设置>编译器>重置默认值 :|