C++ 显示星号密码

时间:2014-06-29 23:57:16   收藏:0   阅读:406


#include <iostream>
#include <vector>
#include <conio.h>
using namespace std;

int main()
{
    vector< char > password;
    int len = 0;
    cout << "Enter password: ";
    while( true ){
        char ch = getch();
        if( ch == 13 )
            break;
        if( ch == 8 ){
            if( len == 0 )
                continue;
            len--;
            cout << "\b \b";
            password.pop_back();
        }
        else{
            len++;
            cout << '*';
            password.push_back( ch );
        }
    }
    cout << endl;
    for( int i = 0; i < password.size(); ++i ){
        cout << password[i];
    }
    return 0;
}


C++ 显示星号密码,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!