"C++ 집합 insert()"의 두 판 사이의 차이

 
(같은 사용자의 중간 판 2개는 보이지 않습니다)
23번째 줄: 23번째 줄:
     pair<set<string>::iterator,bool> p;
     pair<set<string>::iterator,bool> p;
     p = fruits.insert("lemon");
     p = fruits.insert("lemon");
     cout << p.second << endl; // 1 (new element)
     cout << p.second << endl; // 1 (new element inserted)
     p = fruits.insert("apple");
     p = fruits.insert("apple");
     cout << p.second << endl; // 0 (not new element)
     cout << p.second << endl; // 0 (no new element inserted)
}
}


31번째 줄: 31번째 줄:


==같이 보기==
==같이 보기==
{{z컬럼3|
* [[C++ 집합]]
* [[C++ 집합]]
* [[C++ insert()]]
* [[C++ 집합 erase()]]
* [[C++ 집합 erase()]]
* [[C++ 집합 find()]]
* [[C++ 집합 find()]]
* [[C++ 벡터 insert()]]
}}


==참고==
==참고==

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 }}