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

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

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

    posts - 1,  comments - 0,  trackbacks - 0
    find()函數(shù)的偽代碼如下:
    template<class InputIterator, class T>
      InputIterator find ( InputIterator first, InputIterator last, const T& value )
      {
        for ( ;first!=last; first++) if ( *first==value ) break;
        return first;
      }
    一般第一個參數(shù)是迭代器的起始位置,第二參數(shù)是迭代器的結(jié)束位置,第三個參數(shù)是要查找的參數(shù)。當然參數(shù)也可以是數(shù)組名或者指針。如下所示:

     

    #include <iostream>
    #include <algorithm>
    #include <vector>
    using namespace std;
    
    int main () {
      int myints[] = { 10, 20, 30 ,40 };
      int * p;
    
      // pointer to array element:
      p = find(myints,myints+4,30);
      ++p;
      cout << "The element following 30 is " << *p << endl;
    
      vector<int> myvector (myints,myints+4);
      vector<int>::iterator it;
    
      // iterator to vector element:
      it = find (myvector.begin(), myvector.end(), 30);
      ++it;
      cout << "The element following 30 is " << *it << endl;
    
      return 0;
    }

    接收函數(shù)返回值的是一個地址值或者同類型的迭代器。區(qū)分string類的find()函數(shù)。

    通過it==myvector.end()來判斷是否找到此值,相等說明沒找到。
    補充一例:

    泛型算法find的使用(必須包含頭文件algorithm)

     

    2011-01-13 17:11

    #include<iostream>
    #include <algorithm>//使用泛型算法必須包含頭文件algorithm
    #include<vector>
    #include<string>
    using namespace std;
    int main()
    {
     vector<int> ivec;
     while(true)
     {
      cout<<"continue?no(0) yes-enter an int value(not 0):"<<endl;
      int val;
      cin>>val;
      if(val==0)
       break;
      else
       ivec.push_back(val);
     }
     cout<<"please enter int value what you want to find:"<<endl;
     int ival;
     cin>>ival;
     vector<int>::const_iterator cit=find(ivec.begin(),ivec.end(),ival);//find算法是在algorithm中定義的
     cout<<"what you find "<<ival<<(cit==ivec.end()? " is not find" : " found")<<endl;
     return 0;
    }


    刪除容器的操作可見C++primer第四版的9.3.7。

    posted on 2012-04-04 13:23 憤怒的考拉 閱讀(189) 評論(0)  編輯  收藏

    只有注冊用戶登錄后才能發(fā)表評論。


    網(wǎng)站導航:
     
    <2025年5月>
    27282930123
    45678910
    11121314151617
    18192021222324
    25262728293031
    1234567

    常用鏈接

    留言簿

    隨筆檔案

    文章檔案

    搜索

    •  

    最新評論

    主站蜘蛛池模板: 日本人的色道免费网站| 好爽…又高潮了毛片免费看| 久久精品国产亚洲香蕉| 免费黄色福利视频| 99xxoo视频在线永久免费观看| ASS亚洲熟妇毛茸茸PICS| 亚洲性日韩精品国产一区二区| 亚洲视频免费在线看| 一级做a爰片久久毛片免费看| 亚洲短视频男人的影院| 免费A级毛片无码久久版| 久久久久久精品免费看SSS| 色老头永久免费网站| 波多野结衣在线免费视频| 免费毛片在线看不用播放器| 亚洲精华液一二三产区| 久久亚洲精品国产精品| 亚洲片一区二区三区| 免费黄色毛片视频| 1区2区3区产品乱码免费| 久草免费在线观看视频| 大陆一级毛片免费视频观看| 永久免费AV无码网站在线观看| 国产精品免费视频网站| 亚洲视频在线免费播放| 成年女性特黄午夜视频免费看| 国产成人精品久久免费动漫| 三年片在线观看免费大全| 最近免费中文字幕大全免费| 久久亚洲免费视频| 中文精品人人永久免费| 亚洲AV日韩AV永久无码色欲| 亚洲乱码一二三四区乱码| 亚洲精品无码久久久久APP| 亚洲国产模特在线播放| 亚洲一区中文字幕久久| 亚洲中文字幕久久精品蜜桃| 亚洲香蕉在线观看| 无遮挡免费一区二区三区 | 日韩免费无砖专区2020狼| 永久免费毛片在线播放|