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

             

            使用流處理和關聯容器map的解密(詞轉換)程序

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

             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             /*創建密碼表**************************/
            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         /*讀密碼表數據并寫入關聯容器*************/
            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         /*匹配字符串并進行轉換解密**************/
            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;  //以錯誤狀態退出
            73     }
            74 }
            75 
            76 

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

            評論

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

            Good~~  回復  更多評論   

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

            n年前的東西了~~@水色精靈
              回復  更多評論   

            導航

            統計

            常用鏈接

            留言簿(6)

            隨筆分類

            隨筆檔案

            收藏夾

            友情鏈接

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            評論排行榜

            久久久久久九九99精品| 成人午夜精品久久久久久久小说| 人妻精品久久久久中文字幕| 无码任你躁久久久久久老妇| 佐藤遥希在线播放一二区 | 久久综合给合综合久久| 亚洲AV伊人久久青青草原| 99久久国产宗和精品1上映 | 亚洲性久久久影院| 色欲综合久久躁天天躁蜜桃| 国产巨作麻豆欧美亚洲综合久久| 三级韩国一区久久二区综合| 久久久无码精品亚洲日韩按摩| 久久精品视屏| 狠狠干狠狠久久| 亚洲国产精品无码久久| 久久久久国产精品麻豆AR影院| 久久精品国产99久久久 | 亚洲精品无码久久久久久| 91久久成人免费| 99久久99这里只有免费费精品| 欧美无乱码久久久免费午夜一区二区三区中文字幕 | 色婷婷久久综合中文久久一本| 久久亚洲中文字幕精品有坂深雪| 久久综合一区二区无码| 97超级碰碰碰碰久久久久| 久久精品国产亚洲AV高清热| 伊人久久精品无码av一区| 久久亚洲AV永久无码精品| 国产高清美女一级a毛片久久w| 99久久er这里只有精品18| 久久夜色精品国产噜噜噜亚洲AV | 大蕉久久伊人中文字幕| 国产精品久久久久天天影视| 久久久无码人妻精品无码| 性欧美丰满熟妇XXXX性久久久| 久久国产亚洲精品| 国产精品久久久久久五月尺| 久久亚洲国产最新网站| 国产精品亚洲综合久久| 久久人妻AV中文字幕|