zoukankan      html  css  js  c++  java
  • c++输入密码以星号代替

    #include <iostream>
    #include <string>//注意这里的头文件!
    #include<conio.h>
    using namespace std;
    
    void main( void )
    {
     cout<<"请输入密码: "<<endl;
     string password;
     int i=0;
     char ch;
     while ((ch=_getch())!=13)
     {
      password+=ch;//string对象重载了+=
      cout<<"*";
     }
     cout<<endl<<"输入完毕!您输入的是: "<<password<<endl;
    }



    带有退格键的密码输入

    #include<iostream>
    #include<conio.h>
    using namespace std;
    int main()
    {
    char password[100];
    int index=0;
    while(1)
    {
    char ch;
    ch=getch();
    if(ch==8) //退格键
    {
    if(index!=0)
    {
    cout<<char(8)<<" "<<char(8);
    index--;
    }
    }
    else if(ch=='
    ') //回车键
    {
    password[index]='';
    cout<<endl;
    break;
    }
    else
    {
    cout<<"*";
    password[index++]=ch;
    }
    }
    cout<<"password:"<<password<<endl;
    return 0;
    }


  • 相关阅读:
    Design Pattern Explained
    StringBuilder or StringBuffer
    Algorithms
    Difference between pages and blocks
    Date Time Calendar
    Math if fun
    Sublime Text
    Java Regex
    Learning C
    跨域通信/跨域上传浅析
  • 原文地址:https://www.cnblogs.com/oversea201405/p/3766980.html
Copyright © 2011-2022 走看看