record logo record

C++ STL find() 함수

예시 코드(C++)

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;


int main(){

    vector<int> v;

    for(int i = 1; i <= 10; i++) {
        v.push_back(i);
    }

    vector<int>::iterator iter;
    iter = find(v.begin(), v.end(), 7);
    cout << *iter << endl; // 7

    iter = find(v.begin(), v.end(), 100);
    if (iter == v.end()) {
        cout << "Not found!" << endl; // Not found!
    }

    return 0;
}