<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    由于本人要接手一項C++方面 的工作。由于不會C++,不過做過JAVA 以及一些web方面的開發,加之時間比較短。所以需要速成,于是學習筆記也基本都是用代碼代替。

    //范例資源文件
    /*****************************************************************************************
    Test.txt
    :
    tom 123456789
    lilei 234567891
    zhangsan 345678912
    tom 456789123
    xiaohe 567891234????????????????????????????????????????????????????????????????????
    ******************************************************************************************/
    //未用名字空間,使用vector 進行遍歷
    /******************************************************************************************
    #include "stdafx.h"
    #include <iostream>
    #include <string>
    #include <vector>
    #include <fstream>
    int _tmain(int argc,_TCHAR* argv[])
    {
    std::string strtmp;
    std::ifstream fs("Test.txt");
    std::vector<std::string> vect;
    while(getline(fs,strtmp,'\n'))
    {
    vect.push_back(strtmp.substr(0,strtmp.find(" ")));
    }
    for(std::vector<std::string>::size_type index = 0; index < vect.size();index++)
    {
    std::cout << vect[index]?? << std::endl;
    }
    return 0;
    }
    ******************************************************************************************/
    //使用名字空間,使用vector進行遍歷
    /******************************************************************************************
    #include "stdafx.h"
    #include <iostream>
    #include <string>
    #include <vector>
    #include <fstream>
    using namespace std;
    int _tmain(int argc,_TCHAR* argv[])
    {
    string strtmp;
    ifstream fs("Test.txt");
    vector<string> vect;
    while(getline(fs,strtmp,'\n'))
    {
    vect.push_back(strtmp.substr(0,strtmp.find(" ")));
    }
    for(int index = 0; index < vect.size();index++)
    {
    cout << vect[index]?? << endl;
    }
    return 0;
    }
    ******************************************************************************************/
    //利用迭代器,對vector進行遍歷
    /******************************************************************************************
    #include "stdafx.h"
    #include <iostream>
    #include <string>
    #include <vector>
    #include <fstream>
    using namespace std;
    int _tmain(int argc,_TCHAR* argv[])
    {
    ?string strtmp;
    ?ifstream fs("Test.txt");
    ?vector<string> vect;
    ?while(getline(fs,strtmp,'\n'))
    ?{
    ??vect.push_back(strtmp.substr(0,strtmp.find(" ")));
    ?}
    ?vector<string>::iterator it = vect.begin();

    ?for(;it != vect.end();it++)
    ?{
    ??cout << *it? << endl;
    ?}
    ?return 0;
    }
    ******************************************************************************************/
    //使用map 進行遍歷
    /******************************************************************************************
    #include "stdafx.h"
    #include <iostream>
    #include <string>
    #include <vector>
    #include <fstream>
    #include <map>

    using namespace std;

    int _tmain(int argc,_TCHAR* argv[])
    {
    ?string strtmp;
    ?ifstream fs("Test.txt");
    ?map<string,string>? map_temp;
    ?string::size_type index = string::npos;

    ?while(getline(fs,strtmp,'\n'))
    ?{
    ?index = strtmp.find("");
    ?map_temp[strtmp.substr(0,index)] = (strtmp.substr(++index));
    ?}
    ?map<string,string> ::iterator it = map_temp.begin();

    ?for(; it != map_temp.end(); it++)
    ?{
    ??cout << it->first << " = " << it->second << endl;
    ?}
    ?return 0;
    }
    ******************************************************************************************/
    //使用for_each 利用重載操作符 進行map遍歷
    /******************************************************************************************
    #include "stdafx.h"
    #include <iostream>
    #include <string>
    #include <vector>
    #include <fstream>
    #include <map>
    #include <iterator>
    #include <algorithm>

    using namespace std;
    class showIiem
    {
    public:
    void operator()(const map<string,string>::value_type& value)
    {
    cout << value.first << " = " << value.second << "\n";
    };

    };
    int _tmain(int argc,_TCHAR* argv[])
    {
    ?string strtmp;
    ?ifstream fs("Test.txt");
    ?map<string,string>? map_temp;
    ?string::size_type index = string::npos;

    ?while(getline(fs,strtmp,'\n'))
    ?{
    ??index = strtmp.find("");
    ??map_temp[strtmp.substr(0,index)] = (strtmp.substr(++index));
    ?}
    ?showIiem show;
    ?for_each(map_temp.begin(),map_temp.end(),show);
    ?return 0;
    }
    ******************************************************************************************/
    // 利用copy,使用重載操作符 進行map遍歷
    /******************************************************************************************
    #include "stdafx.h"
    #include <string>
    #include <fstream>
    #include <iostream>
    #include <algorithm>
    #include <map>
    #include <vector>

    using namespace std;
    namespace std
    {
    ?std::ostream& operator<<(std::ostream& os, const std::map<std::string,std::string>::value_type& value)
    ?{
    ??os << value.first << "= " << value.second;
    ??return os;
    ?}
    }
    class ShowValue
    {
    public:
    ?ShowValue(std::ostream& os):m_os(os)
    ?{
    ?}

    ?void operator()(const std::map<std::string,std::string>::value_type& value)
    ?{
    ??m_os << value.first << "= " << value.second << "\n";
    ?}
    ?std::ostream& m_os;
    };
    typedef std::ostream_iterator<std::map<std::string,std::string>::value_type> ositertype;
    std::ostream& operator<<(std::ostream& os, const std::map<std::string,std::string>& value)
    {
    ?std::for_each(value.begin(), value.end(), ShowValue(os));
    ?return os;
    }
    int _tmain(int argc,_TCHAR* argv[])
    {
    ?std::string strtmp;
    ?std::fstream in("Test.txt");
    ?std::map<std::string,std::string>? map_1;
    ?std::string::size_type idx = std::string::npos;
    ?while(std::getline(in, strtmp, '\n'))
    ?{
    ??idx = strtmp.find(' ');
    ??map_1[strtmp.substr(0, idx)] = strtmp.substr(++idx);
    ?}
    ?ositertype os_iter(std::cout, "\n");
    ?std::copy(map_1.begin(), map_1.end(), os_iter);
    ?return 0;
    }

    posted on 2008-04-08 23:46 -274°C 閱讀(4019) 評論(0)  編輯  收藏 所屬分類: C++

    常用鏈接

    留言簿(21)

    隨筆分類(265)

    隨筆檔案(242)

    相冊

    JAVA網站

    關注的Blog

    搜索

    •  

    積分與排名

    • 積分 - 914354
    • 排名 - 40

    最新評論

    主站蜘蛛池模板: 好男人看视频免费2019中文| AV无码免费永久在线观看| 亚洲av无码电影网| 无遮挡国产高潮视频免费观看| 91情侣在线精品国产免费| 2022久久国产精品免费热麻豆| 成全视频在线观看免费| 2021在线永久免费视频| 久久久久亚洲AV无码专区首| 亚洲最大激情中文字幕| 国产亚洲精品线观看动态图| 国产一级一片免费播放i| 亚洲一欧洲中文字幕在线| 2021在线观看视频精品免费| 久久久无码精品亚洲日韩按摩 | 免费的一级片网站| 中文字幕天天躁日日躁狠狠躁免费| 你懂的免费在线观看网站| 无码毛片一区二区三区视频免费播放 | 亚洲国产精品白丝在线观看| 香蕉蕉亚亚洲aav综合| 久久er国产精品免费观看8| 国产国产人免费人成免费视频 | 国产大片免费观看中文字幕| 亚洲日本天堂在线| 国产网站免费观看| 精品国产日韩亚洲一区在线| 一个人免费观看视频www| 亚洲另类激情综合偷自拍| 国产JIZZ中国JIZZ免费看| 亚洲情侣偷拍精品| 一个人免费视频在线观看www| 理论秋霞在线看免费| 免费人成视频在线观看视频| jizz免费观看视频| 亚洲一区动漫卡通在线播放| 亚洲第一成人影院| 亚洲成熟丰满熟妇高潮XXXXX| 国产乱辈通伦影片在线播放亚洲| 无码国产精品一区二区免费vr| 亚洲国产精品无码久久一线|