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

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

            STL HASH_MAP簡單應用

            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>/*因為hash_map暫不為CPP標準所以沒辦法寫為<hash_map>*/
            /*-------------------------------------------*/
            using  std::cout;
            using  std::endl;
            using  std::string;
            /*-------------------------------------------*/
            /*函數類
             *作為hash_map的hash函數 
             *string沒有默認的hash函數 
             
            */ 
            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);
                    }
            };
            /*-------------------------------------------*/
            /*函數類 
             *作為hash_map的比較函數 )
             *(查找的時候不同的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簡單應用  回復  更多評論   

            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
            另外,我想問一下,怎么根據keyvalue對hash_map進行排序。
            我的郵箱:crasyman@163.com,能否把你的可執行的工程傳給我?

            # re: STL HASH_MAP簡單應用  回復  更多評論   

            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簡單應用  回復  更多評論   

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

            # re: STL HASH_MAP簡單應用  回復  更多評論   

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

            # re: STL HASH_MAP簡單應用[未登錄]  回復  更多評論   

            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簡單應用  回復  更多評論   

            2009-09-29 23:58 by fall
            VS2008環境下即使添加了using namespace stdext;這句話好像還是不行。
            添加了上面那句話后錯誤信息更多,而且是hash函數內部的錯誤,請教樓主一下,這個問題該怎么解決?謝謝
            亚洲一区二区三区日本久久九| 日批日出水久久亚洲精品tv| …久久精品99久久香蕉国产| 久久精品中文无码资源站| 午夜精品久久久久久中宇| 亚洲精品高清久久| 久久久久亚洲AV成人网人人网站 | 亚洲日韩中文无码久久| 久久青青草原亚洲av无码app| 蜜桃麻豆www久久| 一本色道久久88综合日韩精品| 欧美一区二区三区久久综合| 色综合久久中文综合网| 色欲综合久久躁天天躁| 久久电影网一区| 国产偷久久久精品专区| 精品国产乱码久久久久久浪潮| 久久精品国产免费观看 | 国产成人精品久久亚洲高清不卡| 久久精品国产一区二区三区不卡| 色综合久久久久无码专区| 精品国产91久久久久久久a| 午夜精品久久久久久毛片| 亚洲国产婷婷香蕉久久久久久| 久久超碰97人人做人人爱| 久久这里都是精品| 精品久久久久久无码国产| 97精品久久天干天天天按摩 | 久久天天躁狠狠躁夜夜躁2014| 99久久伊人精品综合观看| 精品乱码久久久久久久| 中文字幕久久久久人妻| 人人狠狠综合久久亚洲高清| 日本一区精品久久久久影院| 精品乱码久久久久久久| 国产精品久久久久久久| 国产三级久久久精品麻豆三级 | 91精品日韩人妻无码久久不卡| 久久不见久久见免费视频7| 国产69精品久久久久777| 国产精品99久久久久久人|