개요
- C++ 집합 find()
- C++ 집합 원소 있는지 확인
#include <iostream>
#include <set>
using namespace std;
int main() {
set<string> s = {"apple", "banana", "cherry"};
cout << (s.find("apple") != s.end()) << endl; // 1
cout << (s.find("lemon") != s.end()) << endl; // 0
}
#include <iostream>
#include <set>
using namespace std;
int main() {
set<int> myset;
for (int i=1; i<=5; i++) myset.insert(i*10); // set: 10 20 30 40 50
myset.erase(myset.find(20));
myset.erase(myset.find(40));
for(auto& el: myset) cout << el << ' '; // 10 30 50
}