C++ set demo

#include <iostream>
#include <set>
using namespace std;
void PrintS(set<int> s_int){
    cout<<"Print:";
    for (set<int>::iterator  it = s_int.begin(); it !=s_int.end() ; ++it) {
        cout<<*it<<" ";
    }
    cout<<endl;
}
int main() {
    std::cout << "Hello, World!" << std::endl;
    set<int> s_int{1,2,3,4,5,6,7};
    PrintS(s_int);
    s_int.erase(s_int.find(3));
    PrintS(s_int);
    s_int.insert(9);
    PrintS(s_int);
    s_int.insert(3);
    PrintS(s_int);
    return 0;
}

显示:

Print:1 2 3 4 5 6 7
Print:1 2 4 5 6 7
Print:1 2 4 5 6 7 9
Print:1 2 3 4 5 6 7 9

猜你喜欢

转载自www.cnblogs.com/liuguoyao514257665/p/11204451.html
今日推荐