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

            newplan

            阿基米德在洗澡時發(fā)現(xiàn)浮力原理,高興得來不及穿上褲子,跑到街上大喊:Eureka(我找到了)。
            posts - 39, comments - 26, trackbacks - 0, articles - 4
              C++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

            STL HASH_MAP簡單應(yīng)用

            Posted on 2008-05-05 17:17 山泉彎延 閱讀(14547) 評論(6)  編輯 收藏 引用
            /*
             *用來測試STL hash_map 
             *簡單例子2008.5.5
            */
            #include  
            <cstdlib>
            #include  
            <iostream>
            #include  
            <string>
            #include  
            <hash_map.h>/*因為hash_map暫不為CPP標(biāo)準(zhǔn)所以沒辦法寫為<hash_map>*/
            /*-------------------------------------------*/
            using  std::cout;
            using  std::endl;
            using  std::string;
            /*-------------------------------------------*/
            /*函數(shù)類
             *作為hash_map的hash函數(shù) 
             *string沒有默認(rèn)的hash函數(shù) 
             
            */ 
            class str_hash{
                  
            public:
                   size_t 
            operator()(const string& str) const
                    {
                            unsigned 
            long __h = 0;
                            
            for (size_t i = 0 ; i < str.size() ; i ++)
                            __h 
            = 5*__h + str[i];
                            
            return size_t(__h);
                    }
            };
            /*-------------------------------------------*/
            /*函數(shù)類 
             *作為hash_map的比較函數(shù) )
             *(查找的時候不同的key往往可能對用到相同的hash值
            */ 
            class str_compare
            {
                  
            public:
                         
            bool operator()(const string& str1,const string& str2)const
                         {
            return   str1==str2;}
            };
            /*-------------------------------------------*/
            int 
            main(
            int argc, char *argv[])
            {  
                hash_map
            <string,string,str_hash,str_compare>  myhash;
                
                myhash[
            "google"]="newplan";
               
                myhash[
            "baidu"]="zhaoziming";
               
                
            if(myhash.find("google")!=myhash.end())
                  cout
            <<myhash["google"]<<endl;
                
                system(
            "PAUSE");
                
                
            return EXIT_SUCCESS;
            }
            /*-------------------------------------------*/

            Feedback

            # re: STL HASH_MAP簡單應(yīng)用  回復(fù)  更多評論   

            2008-08-12 12:58 by 陳盛
            我在.net2005上怎么運行不了你的代碼?編譯不通過,說:
            錯誤 1 fatal error C1083: Cannot open include file: 'hash_map.h': No such file or directory f:\private\vc++\testhashmap\testhashmap\testhashmap.cpp 8
            另外,我想問一下,怎么根據(jù)keyvalue對hash_map進(jìn)行排序。
            我的郵箱:crasyman@163.com,能否把你的可執(zhí)行的工程傳給我?

            # re: STL HASH_MAP簡單應(yīng)用  回復(fù)  更多評論   

            2008-09-27 17:16 by rubby
            fatal error C1083: Cannot open include file: 'hash_map.h': No such file or directory

            # re: STL HASH_MAP簡單應(yīng)用  回復(fù)  更多評論   

            2008-12-08 14:38 by xiong
            你好! 我是在vc6下想用hashmap ,要加stlport 但還是不能用。能告訴我你是怎樣讓hashmap能用的嗎?謝謝你啦~我郵箱xiongzhanying@126.com

            # re: STL HASH_MAP簡單應(yīng)用  回復(fù)  更多評論   

            2008-12-13 19:10 by 山泉彎延
            我的運行環(huán)境是DEV,你可以子DEV的安裝包中找到該文件HASH_MAP.H,至于其他的IDE我還沒有去考慮過,不過你可以馬上查@xiong

            # re: STL HASH_MAP簡單應(yīng)用[未登錄]  回復(fù)  更多評論   

            2009-04-24 08:48 by kevin
            at VS 2005,

            #include <iostream>
            #include <string>
            #include <hash_map>

            using namespace stdext;
            using namespace std;

            int _tmain(int argc, _TCHAR* argv[])
            {
            hash_map<string,string> myhash;

            myhash["google"]="newplan";

            myhash["baidu"]="zhaoziming";

            if(myhash.find("google")!=myhash.end())
            cout<<myhash["google"]<<endl;

            system("PAUSE");

            return EXIT_SUCCESS;
            }

            # re: STL HASH_MAP簡單應(yīng)用  回復(fù)  更多評論   

            2009-09-29 23:58 by fall
            VS2008環(huán)境下即使添加了using namespace stdext;這句話好像還是不行。
            添加了上面那句話后錯誤信息更多,而且是hash函數(shù)內(nèi)部的錯誤,請教樓主一下,這個問題該怎么解決?謝謝

            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            国产精品久久网| 99久久人妻无码精品系列| 久久涩综合| 国产成人精品久久| 91久久九九无码成人网站| 欧美性大战久久久久久| 色综合久久久久综合体桃花网| 久久香蕉综合色一综合色88| 午夜精品久久久久成人| 波多野结衣中文字幕久久| 久久激情五月丁香伊人| 国产精品福利一区二区久久| 亚洲国产高清精品线久久| 久久se精品一区二区| 亚洲精品无码专区久久久| 欧美精品一区二区久久| 国内精品久久久久| 久久精品aⅴ无码中文字字幕不卡 久久精品aⅴ无码中文字字幕重口 | 久久人人爽人爽人人爽av| 日韩人妻无码一区二区三区久久| 久久久久99精品成人片牛牛影视| 久久久免费精品re6| 国产欧美久久久精品影院| 国产高潮国产高潮久久久91| 久久国产精品99国产精| 亚洲中文精品久久久久久不卡| 久久精品人妻一区二区三区| 日韩亚洲欧美久久久www综合网| 久久精品国产亚洲av高清漫画| 国产毛片欧美毛片久久久| 国内精品九九久久精品 | 久久久久久久精品成人热色戒 | 久久久这里只有精品加勒比| 国产精品一区二区久久精品无码| 狠狠色婷婷久久一区二区三区| 久久亚洲AV成人无码电影| 国产精品免费福利久久| 久久精品中文字幕久久| 国产精品热久久无码av| 国内精品久久久久久中文字幕| 久久精品一区二区三区中文字幕|