您的位置:首页 > 编程语言 > C语言/C++

c++ primer习题9.13

2013-08-22 16:25 232 查看
#include <iostream>
#include <vector>
#include <list>
using namespace std;

template<typename T1, typename T2>
T1 findInt(T1 beg, T1 end, T2 ival)
{
    while(beg!=end)
    {
        if(*beg==ival)
            break;
        else
            ++beg;
    }
    return beg;
}

int main()
{
    int ia[]={0,1,2,3,4,5,6,7,8};
    vector<int> ivec(ia, ia+9);
    cout<<"Enter a integer:"<<endl;
    int ival;
    cin>>ival;
    vector<int>::iterator it;
    it=findInt(ivec.begin(), ivec.end(), ival);
    if(it!=ivec.end())
        cout<<ival<<" is a element of the vector."<<endl;
    else
        cout<<ival<<" is not a element of the vector."<<endl;
    return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: