C++ 집합 insert()

Jmnote (토론 | 기여)님의 2023년 9월 10일 (일) 12:19 판
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

1 개요[ | ]

C++집합 insert()
#include <iostream>
#include <set>
using namespace std;

int main() {
    set<int> myset;
    for (int i=1; i<=5; i++) {
        myset.insert(i*10);
    }
    for(auto& el: myset) cout << el << ' '; // 10 20 30 40 50
}
#include <iostream>
#include <set>
using namespace std;
int main() {
    set<string> fruits = {"apple", "banana", "cherry"};
    pair<set<string>::iterator,bool> p;
    p = fruits.insert("lemon");
    cout << p.second << endl; // 1 (new element inserted)
    p = fruits.insert("apple");
    cout << p.second << endl; // 0 (no new element inserted)
}

2 같이 보기[ | ]

3 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}