1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
std::set<int> myset; myset.insert(100); myset.insert(200); myset.clear();
if (myset.count(i) != 0) std::cout << " is an element of myset.n"; else std::cout << " is not an element of myset.n";
{ // cbegin/cend(c++11): Returns a const_iterator pointing to the first element in the container/ // Returns a const_iterator pointing to the past-the-end element in the container std::set<int> myset = { 50, 20, 60, 10, 25 };
std::cout << "myset contains:"; for (auto it = myset.cbegin(); it != myset.cend(); ++it) std::cout << ' ' << *it;
std::cout << 'n'; }
{ // crbegin/crend(c++11):Return const_reverse_iterator to reverse beginning/ // Return const_reverse_iterator to reverse end std::set<int> myset = { 50, 20, 60, 10, 25 };
std::cout << "myset backwards:"; for (auto rit = myset.crbegin(); rit != myset.crend(); ++rit) std::cout << ' ' << *rit;
std::cout << 'n'; }
|
近期评论