标签:begin div nta into using set second contain header
#include <iostream>
#include<set>
using namespace std;
int main(){
int numList[6]={1,2,2,3,3,3};
//1.set add
set<int> numSet;
for(int i=0;i<6;i++)
{
//2.1insert into set
numSet.insert(numList[i]);
}
//2.travese set
for(set<int>::iterator it=numSet.begin() ;it!=numSet.end();it++)
{
cout<<*it<<" occurs "<<endl;
}
//3.set find useage
int findNum=1;
if(numSet.find(findNum)!=numSet.end())
{
cout<<"find num "<<findNum<<" in set"<<endl;
}else{
cout<<"do not find num in set"<<findNum<<endl;
}
//set delete useage
int eraseReturn=numSet.erase(1);
if(1==eraseReturn)
{
cout<<"erase num 1 success"<<endl;
}else{
cout<<"erase failed,erase num not in set"<<endl;
}
return 0;
}
#include <iostream>
#include <map>
using namespace std;
int main(){
map<int,int> m;
for (int i = 0; i < 10; i++){
m[i] = i*i;
}
map<int,int>::iterator iter;
iter = m.begin();
while(iter != m.end()){
cout << iter->first << "-" << iter->second << endl;
iter++;
}
for (iter = m.begin();iter != m.end(); iter++){
cout << iter->first << "-" << iter->second << endl;
}
for(auto &it : m){
cout << it.first << "-" << it.second <<endl;
}
return 0;
}
标签:begin div nta into using set second contain header
原文地址:https://www.cnblogs.com/houzm/p/12860348.html