#include #include #include #include using namespace std; vector v1; vector v2(10); //空间大小 vector v3(5,3); //空5,所有元素为3 vector v4(v3); //内容为 v3

int a[10]={1,2,3,4,5,6,7,8,9,10}; vector v5(a,a+5); //拷贝a前五个元素

//push_back(x) 末尾加 //pop_back() //front() 访问第一个 //back() //erase(x) !删指定位置元素 ! //size() 元素个数 //empty() //clear() 清空 //begin() !获第一个元素的迭代器! //end()-1 !最后一个元素的迭代器!

//迭代器(指针)

//集合(set):有序,元素不重复 !!! //multiset :有重复的集合

set s1; set s2(s1);

int aa[10]={1,2,3,4,5,6,7,8,9,10}; set<int,greater> s3(aa,aa+10); //拷贝0,9 greater(降序) //insert(x) 往集合中添加一元素 //find(x) 查找x是否出现过,找到就返回对应的迭代器,否则返回end() //erase(x) 删除x元素

//迭代器 set::iterator it;

//哈希表(map): 提供一对一数据存储结构,【键-值】 map<string,int> mp;

//insert({k,v}) :往哈希表里添一个键值对 //find(x) 查找x是否出现过,找到就返回对应的迭代器,否则返回end()

//count(x) 统计键值x出现几次,因为键只出1次,所以只返回0或1 //erase(x) 删键 x

//迭代器 map<string,int>::iterator ii;

int main(){ if(mp.find("hh")!= mp.end()){ //YES } ii="wanglvyan",cout<<ii.first<<" "<<ii.second; //键值 mp.insert({"wanglvyan",100}); for(auto i: mp){ cout<<i.first<<" "<<i.second; } return 0; }

1 条评论

  • @ 2024-5-4 17:13:11

    dddffgghgh[ftfhdted[[[[[[[[[[](https://)](https://)](https://)](https://)](https://)](https://)](https://)](https://)](https://)](https://)](https://)

    • 1