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

(새 문서: ==개요== ;C++집합 insert() <syntaxhighlight lang='cpp' run> #include <iostream> #include <set> using namespace std; int main() { set<int> myset; for (int i=1; i<=5; i++)...)
 
 
(같은 사용자의 중간 판 5개는 보이지 않습니다)
15번째 줄: 15번째 줄:
}
}
</syntaxhighlight>
</syntaxhighlight>
<syntaxhighlight lang='cpp' run>
#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)
}


</syntaxhighlight>


==같이 보기==
==같이 보기==
{{z컬럼3|
* [[C++ 집합]]
* [[C++ 집합]]
* [[C++ insert()]]
* [[C++ 집합 erase()]]
* [[C++ 집합 erase()]]
* [[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 }}