Skip to content

Instantly share code, notes, and snippets.

@MasazI
Created May 25, 2015 05:16
Show Gist options
  • Save MasazI/e49d79ee6e273a8c95c0 to your computer and use it in GitHub Desktop.
Save MasazI/e49d79ee6e273a8c95c0 to your computer and use it in GitHub Desktop.
set.cpp
//
// set.cpp
// CplusplusPractice
//
// Created by masai on 2015/05/25.
// Copyright (c) 2015年 masai. All rights reserved.
//
#include <iostream>
#include <set>
using namespace std;
int main(int argc, char* argv[]){
set<int> s;
// insert
s.insert(1);
s.insert(2);
s.insert(3);
s.insert(4);
s.insert(5);
// setの要素数
cout << "set cnt is " << s.size() << endl;
// 保持している要素は、iteratorを受け取ることができる
set<int>::iterator i = s.find(3);
if(i == s.end()){
cout << "can not find." << endl;
}else{
cout << "find " << *i << endl;
}
// 保持していない要素は、iterator end()を受け取ることができる
set<int>:: iterator i_c = s.find(10);
if(i_c == s.end()){
cout << "can not find 10" << endl;
}else{
cout << *i << endl;
}
// 要素の削除
s.erase(3);
set<int>:: iterator i_e = s.find(3);
if(i_e == s.end()){
cout << "can not find 3" << endl;
}else{
cout << *i << endl;
}
// setの要素数
cout << "set cnt is " << s.size() << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment