• <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 山泉彎延 閱讀(14544) 評論(6)  編輯 收藏 引用
            /*
             *用來測試STL hash_map 
             *簡單例子2008.5.5
            */
            #include  
            <cstdlib>
            #include  
            <iostream>
            #include  
            <string>
            #include  
            <hash_map.h>/*因?yàn)閔ash_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上怎么運(yùn)行不了你的代碼?編譯不通過,說:
            錯誤 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 山泉彎延
            我的運(yùn)行環(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   管理


            亚洲一区中文字幕久久| 亚洲欧美日韩久久精品第一区| 欧美丰满熟妇BBB久久久| 少妇内射兰兰久久| 国产91色综合久久免费| 久久久久成人精品无码| 亚洲欧美成人综合久久久| 久久99国产精一区二区三区| 久久天天躁狠狠躁夜夜2020老熟妇| 亚洲国产精品嫩草影院久久| 久久精品无码一区二区无码| 无码国内精品久久人妻麻豆按摩| 久久亚洲精精品中文字幕| 久久综合色区| 精品一区二区久久久久久久网站| 香蕉久久影院| 国产成人99久久亚洲综合精品| 国产成人无码精品久久久性色| 成人午夜精品久久久久久久小说| 国产成年无码久久久免费| 久久国产视频网| 91精品国产91久久久久久| 久久无码人妻一区二区三区午夜| 久久久久久久久66精品片| 国产福利电影一区二区三区久久老子无码午夜伦不 | 精品久久久久久中文字幕人妻最新| www性久久久com| 97精品伊人久久久大香线蕉 | 久久er热视频在这里精品| 久久久久久久久久久久久久| 精品人妻伦一二三区久久| 99久久久国产精品免费无卡顿 | 久久久亚洲AV波多野结衣| 久久九九久精品国产| 青青草原1769久久免费播放| 久久99国产综合精品| 无码人妻久久一区二区三区| 亚洲国产精品久久久天堂| 亚洲精品乱码久久久久久蜜桃图片| 伊人色综合九久久天天蜜桃| 国产香蕉97碰碰久久人人|