• <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 山泉彎延 閱讀(14547) 評論(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函數內部的錯誤,請教樓主一下,這個問題該怎么解決?謝謝
            久久www免费人成精品香蕉| 中文成人无码精品久久久不卡| 久久久亚洲AV波多野结衣| 久久国产高潮流白浆免费观看| 久久成人18免费网站| 亚洲&#228;v永久无码精品天堂久久| 久久久久久久精品妇女99| 无码专区久久综合久中文字幕 | 国产情侣久久久久aⅴ免费| 思思久久99热免费精品6| 亚洲国产另类久久久精品| 一本久久久久久久| 久久九九有精品国产23百花影院| 久久99精品久久久久久动态图 | 久久99毛片免费观看不卡| 亚洲欧美日韩中文久久| 91精品国产91热久久久久福利 | 日本人妻丰满熟妇久久久久久| 热久久最新网站获取| 日韩电影久久久被窝网| 青青草国产精品久久| 久久香蕉国产线看观看精品yw | 久久国产亚洲精品无码| 久久人妻AV中文字幕| 久久久噜噜噜久久| 污污内射久久一区二区欧美日韩 | 久久久综合九色合综国产| 久久精品国产2020| 模特私拍国产精品久久| 亚洲人成无码久久电影网站| 久久国产成人| 久久影视国产亚洲| 亚洲精品视频久久久| 亚洲а∨天堂久久精品| 色综合合久久天天给综看| 青青青青久久精品国产h久久精品五福影院1421| 久久99精品久久只有精品 | 蜜臀av性久久久久蜜臀aⅴ麻豆| 久久无码高潮喷水| 97精品国产91久久久久久| 久久伊人五月天论坛|