• <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>

            2009年5月21日

            struct 與class 的區(qū)別

            以前一直沒有明白struct結(jié)構(gòu)體與class類 的區(qū)別:
            (1)
                 名字不同一個是struct,一個是class
            (2)
              默認(rèn)的訪問屬性不同 struct是public,class 是private

            posted @ 2009-05-21 22:19 彈杯一笑 閱讀(233) | 評論 (0)編輯 收藏

            2009年5月12日

            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 @ 2009-05-12 10:44 彈杯一笑 閱讀(875) | 評論 (0)編輯 收藏

            2009年4月1日

            N皇后問題求解

                 摘要: //N皇后問題求解(此處為8皇后)   1#include <iostream>  2#include <cstdio>  3#include <ctime>  4#include <cmath>   ...  閱讀全文

            posted @ 2009-04-01 23:17 彈杯一笑 閱讀(421) | 評論 (0)編輯 收藏

            2009年3月30日

            如何設(shè)計一個范型算法

            // essential  c++
            向一個容器(比如 vector)中添加數(shù)字后,然后隨便輸入待比較的數(shù)字( int a ;),求找出在vector中比a大的數(shù)字,比a小的數(shù)字,和a相等的數(shù)字,或者是a的3倍,5倍等之類的數(shù)字的集合.

            //開始看下面的代碼之前,你是怎么思考的呢?你是不是覺得直接在里面寫個函數(shù)比較就是了?或者是其他的呢?

             1#include<iostream>
             2#include <vector>
             3#include <string>
             4using namespace std;
             5/*
             6* 單獨寫出相關(guān)的函數(shù)  如 比較,倍數(shù)之類的,后面調(diào)用 。
             7* 此處僅寫了小于和大于函數(shù)   其他的依次類推。
             8* 注意參數(shù) 與指針函數(shù)的匹配
             9*/

            10bool less_than(int v1,int v2)
            11{
            12     return v1<v2?true:false;
            13}

            14bool greater_than(int v1,int v2)
            15{
            16     return v1 > v2 ? true:false;
            17}

            18
            19vector<int> filter_ver1(const vector<int> &vec,int filter_value,bool(*pred)(int,int))         
            20
            21//個人覺得這個函數(shù)設(shè)置得很好,用到函數(shù)指針傳遞相關(guān)的函數(shù)。注意相關(guān)形參的匹配
            22{           
            23            vector<int> nvec;
            24            for(size_t ix = 0;ix != vec.size(); ++ix)
            25                    if(pred(vec [ix],filter_value))            //  調(diào)用相關(guān)函數(shù)進(jìn)行操作
            26                    nvec.push_back(vec[ix]);           //滿足結(jié)果就保存
            27            return nvec;
            28}

            29int main()
            30{   
            31    int value;
            32    vector<int> ivec; 
            33    cout <<"請輸入數(shù)字:  "<<endl;
            34    while(cin >> value)
            35    ivec.push_back(value);
            36    cin.clear();             //使輸入流有效
            37    int ival;
            38    cout<<"請輸入你要比較數(shù)字: "<<endl;
            39    cin >>ival;
            40    vector<int> vec=filter_ver1(ivec,ival ,greater_than);  // 函數(shù)的調(diào)用  傳遞函數(shù)名即可
            41    vector<int>::iterator it=vec.begin();
            42    while(it!= vec.end())
            43               cout<<*it++<<"  ";
            44               cout<<endl;
            45
            46    system("pause");
            47    return 0;
            48}

            posted @ 2009-03-30 23:54 彈杯一笑 閱讀(405) | 評論 (0)編輯 收藏

            僅列出標(biāo)題  
            <2025年7月>
            293012345
            6789101112
            13141516171819
            20212223242526
            272829303112
            3456789

            導(dǎo)航

            統(tǒng)計

            常用鏈接

            留言簿(2)

            隨筆分類(7)

            隨筆檔案(4)

            搜索

            最新評論

            閱讀排行榜

            評論排行榜

            亚洲国产成人久久综合一| 国产成人无码精品久久久久免费| 2020久久精品国产免费| 成人久久免费网站| 精品国产99久久久久久麻豆| 伊人色综合久久天天网| 一本综合久久国产二区| 亚洲人AV永久一区二区三区久久 | 国产精品成人99久久久久| 久久国产亚洲精品无码| 麻豆AV一区二区三区久久| 亚洲国产精品无码久久久蜜芽| 久久夜色精品国产亚洲| 亚州日韩精品专区久久久| 蜜桃麻豆www久久国产精品| 久久青青色综合| 欧美va久久久噜噜噜久久| 精品久久久久久亚洲| 青青青青久久精品国产| 久久久WWW免费人成精品| 一本大道久久东京热无码AV | 综合久久国产九一剧情麻豆| 亚洲va国产va天堂va久久| 国产精品无码久久久久久| 国产精品免费久久| 久久久久久久久66精品片| 久久超乳爆乳中文字幕| 品成人欧美大片久久国产欧美| 青青热久久国产久精品| 久久亚洲私人国产精品vA| 国产午夜精品理论片久久| 久久精品亚洲AV久久久无码| 97久久国产亚洲精品超碰热| 久久国产成人午夜AV影院| 亚洲精品无码久久一线| 国产精品xxxx国产喷水亚洲国产精品无码久久一区 | 精品久久久久久无码国产| 亚洲国产精品无码成人片久久| 精品一区二区久久| 精品国产乱码久久久久久呢| 精品久久人人妻人人做精品|