• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            C/C++: 控制臺輸入密碼, 用*號掩藏

            //此代碼有一個網(wǎng)友所寫

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

            /**
             * 秘密在于conio.h中的getch()從鍵盤中讀取字符時,并不會在屏幕上輸出已經(jīng)輸入的字符,
             * 而用一個putch('*')來哄騙,代表已經(jīng)輸入一個字符
             * 怪不得這個頭文件要叫conio.h, con的意思就有哄騙,看來就是由此而來.
             
            */


            using namespace std;

            int main() {
                    
            char* password;
                    
            char* passwordConfirm;

                    
            int length = 4;
                    password 
            = new char[length + 1];
                    passwordConfirm 
            = new char[length + 1];

                    
            char* p = NULL;
                    
            int count = 0;

                    cout 
            << "Input password : ";
                    p 
            = password;
                    count 
            = 0;
                    
            //fflush(stdin);
                    while (((*= getch()) != 13&& count < length) {
                            
            // 這里不是'\n'(10), new line
                            
            // 而是'\r'(13), reback. 即是按下回車鍵,好像這個東西是linux的.
                            
            // 主要是與getch這個函數(shù)有關(guān).
                            putch('*');
                            fflush(stdin);

                            p
            ++;
                            count
            ++;
                    }

                    password[count] 
            = '\0';

                    cout 
            << endl << "Confirm the password : ";
                    p 
            = passwordConfirm;
                    count 
            = 0;
                    
            //fflush(stdin);
                    while (((*= getch()) != 13&& count < length) {
                            putch(
            '*');
                            fflush(stdin);

                            p
            ++;
                            count
            ++;
                    }

                    passwordConfirm[count] 
            = '\0';

                    cout 
            << endl;
                    
            if (strcmp(password, passwordConfirm) == 0{
                            cout 
            << "The password is right." << endl;
                            cout 
            << password << endl;
                    }
             else {
                            cout 
            << "Confirm password fail." << endl;
                            cout 
            << password << endl << passwordConfirm << endl;
                    }


                    
            return 0;
            }


            posted on 2009-05-12 10:44 彈杯一笑 閱讀(875) 評論(0)  編輯 收藏 引用 所屬分類: c++筆記

            <2025年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            導(dǎo)航

            統(tǒng)計

            常用鏈接

            留言簿(2)

            隨筆分類(7)

            隨筆檔案(4)

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            精品综合久久久久久98| 欧美日韩精品久久久久| 国内精品久久久久影院日本| MM131亚洲国产美女久久| 国产精品久久久久久福利漫画| 久久99精品国产麻豆宅宅 | 久久丝袜精品中文字幕| 人妻中文久久久久| 久久永久免费人妻精品下载| 日韩亚洲欧美久久久www综合网 | 久久久久99精品成人片牛牛影视| 无码任你躁久久久久久| 久久丫精品国产亚洲av| 国产高潮久久免费观看| 少妇久久久久久被弄高潮| 亚洲国产天堂久久综合网站| 97视频久久久| 九九久久精品国产| 久久精品黄AA片一区二区三区| 日本久久中文字幕| 久久美女网站免费| 奇米综合四色77777久久| 久久综合久久鬼色| 亚洲成色999久久网站| 婷婷综合久久中文字幕蜜桃三电影| 久久久精品久久久久特色影视| 久久久国产精品亚洲一区| 国产精品成人久久久| 久久精品国产WWW456C0M| 久久亚洲精品视频| 99久久无色码中文字幕| 性色欲网站人妻丰满中文久久不卡| 久久青青草原精品国产软件| 国产精品久久久久久久久久免费| 国产精品美女久久久久网| 无码人妻精品一区二区三区久久久| 性高朝久久久久久久久久| 欧美一级久久久久久久大| 久久久久久亚洲精品不卡| 欧美大战日韩91综合一区婷婷久久青草| 国产精品久久久久天天影视|