std::set の要素参照
std::set は二分探索木での実装なので operator[] でアクセスできない.イテレータを使う.
#include <bits/stdc++.h> using namespace std; int main(){ set<int> st{3, 1, 4}; for (auto itr = st.begin(); itr != st.end(); ++itr) { cout << *itr << endl; } return 0; }
1 3 4
std::set は二分探索木での実装なので operator[] でアクセスできない.イテレータを使う.
#include <bits/stdc++.h> using namespace std; int main(){ set<int> st{3, 1, 4}; for (auto itr = st.begin(); itr != st.end(); ++itr) { cout << *itr << endl; } return 0; }
1 3 4