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

            上善若水,厚德載物

            大道無親 大象無形 大音希聲 大巧若拙 大智若愚 【From small beginnings comes great things.】

             

            使用流處理和關(guān)聯(lián)容器map的解密(詞轉(zhuǎn)換)程序

                  最近看到有關(guān)容器與流處理的部分內(nèi)容,看到書上關(guān)于一段單詞轉(zhuǎn)化的代碼,看上去感覺比較亂==b,按著自己的思路再寫一遍:-)
                  該程序會(huì)在你電腦的D盤生成(或者你自己寫一個(gè))密碼表的password list.txt文件,寫入亂碼和解密后的正確字符串;然后同樣是在D盤找到需要解密的input.txt文件對(duì)里面的文檔進(jìn)行轉(zhuǎn)換.

             1 #include <iostream>
             2 #include <fstream>
             3 #include <sstream>
             4 #include <map>
             5 #include <string>
             6 
             7 using namespace std;
             8 
             9 int main()
            10 
            11     try
            12     {
            13         map<string,string> trans_map;
            14         string key,value;
            15         char isContinue = 'y',BuildList = 'a';
            16         fstream map_file;
            17         cout<<"Already have a password list(a) or want to bulid a new one(b)?\n";
            18         cin>>BuildList;
            19         if(BuildList == 'b')
            20         {
            21             cout<<"Please build and input the password list: \n";
            22             map_file.open("d:\\password list.txt",ios::out);
            23             if(!map_file)
            24                 throw std::runtime_error("Password list_File cannot be opened!");
            25             /*創(chuàng)建密碼表**************************/
            26             while(isContinue == 'y')
            27             {
            28                 cin>>key>>value;
            29                 map_file<<key<<" "<<value<<'\n';
            30                 trans_map.insert(make_pair(key,value));
            31                 cout<<"Continue?(y/n)\n";
            32                 cin>>isContinue;
            33             }
            34             map_file.close();
            35         }
            36         cout<<"Password list is successfully builded!"<<endl;
            37         map_file.open("d:\\password list.txt",ios::in);
            38         if(!map_file)
            39             throw std::runtime_error("Password list_File cannot be opened!");
            40         /*讀密碼表數(shù)據(jù)并寫入關(guān)聯(lián)容器*************/
            41         while(map_file>>key>>value)
            42         {
            43             trans_map.insert(make_pair(key,value));
            44         }
            45         map_file.close();
            46         fstream input_file;
            47         input_file.open("d:\\input.txt",ios::in);
            48         if(!input_file)
            49             throw std::runtime_error("Input_File cannot be opened!");
            50         string line;
            51         /*匹配字符串并進(jìn)行轉(zhuǎn)換解密**************/
            52         while(getline(input_file,line))
            53         {
            54             //映射入字符串流
            55             istringstream stream(line);
            56             string word;
            57             while(stream>>word)
            58             {
            59                 map<string,string>::const_iterator map_it = trans_map.find(word);
            60                 if(map_it != trans_map.end())
            61                     word = map_it->second;
            62                 cout<<word<<" ";
            63             }
            64             cout<<endl;
            65         }
            66         input_file.close();
            67         return 0;
            68     }
            69     catch(std::exception const &ex)
            70     {
            71         cerr<<ex.what()<<endl;
            72         return EXIT_FAILURE;  //以錯(cuò)誤狀態(tài)退出
            73     }
            74 }
            75 
            76 

            posted on 2009-06-24 11:12 ChenZB 閱讀(353) 評(píng)論(2)  編輯 收藏 引用 所屬分類: C++

            評(píng)論

            # re: 使用流處理和關(guān)聯(lián)容器map的解密(詞轉(zhuǎn)換)程序 2009-08-17 22:22 水色精靈

            Good~~  回復(fù)  更多評(píng)論   

            # re: 使用流處理和關(guān)聯(lián)容器map的解密(詞轉(zhuǎn)換)程序 2009-08-17 22:24 ChenZB

            n年前的東西了~~@水色精靈
              回復(fù)  更多評(píng)論   

            導(dǎo)航

            統(tǒng)計(jì)

            常用鏈接

            留言簿(6)

            隨筆分類

            隨筆檔案

            收藏夾

            友情鏈接

            搜索

            積分與排名

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            亚洲?V乱码久久精品蜜桃| 久久国产高清字幕中文| 狠狠色综合网站久久久久久久高清| 久久精品综合一区二区三区| 日韩人妻无码一区二区三区久久99| 久久亚洲精品国产精品| 91精品国产高清久久久久久91| 久久免费视频6| 久久香综合精品久久伊人| 亚洲国产精品久久66| 亚洲国产另类久久久精品黑人 | 久久综合九色综合久99| 亚洲色欲久久久综合网| 精品久久久久久国产牛牛app| 亚洲成色WWW久久网站| 国产国产成人久久精品| 久久A级毛片免费观看| 亚洲国产精品狼友中文久久久| 国产午夜久久影院| 日韩人妻无码一区二区三区久久| 欧美日韩精品久久久久| 久久噜噜电影你懂的| 久久亚洲日韩精品一区二区三区| 亚洲国产成人精品91久久久| 久久国产精品免费一区二区三区| 国产三级久久久精品麻豆三级| 久久久久人妻一区二区三区| 日本亚洲色大成网站WWW久久| 青青草原综合久久大伊人精品| 看久久久久久a级毛片| 国产亚洲精品久久久久秋霞| 精品久久久久久久久免费影院 | 久久综合日本熟妇| 狠狠综合久久综合中文88 | 久久精品这里只有精99品| 国产午夜福利精品久久| 国产激情久久久久影院小草| 99久久精品免费观看国产| 亚洲国产二区三区久久| 国产精品日韩欧美久久综合| 三级片免费观看久久|