标签:
vector的练习不是很完整,希望能在处理现实问题的时候能够进行补全,看了一些网络上的东西自己试着写了些
#include<iostream>
#include<map>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
bool cmp(int a,int b)
{
return a>b;
}
int main()
{
vector<int> m;
for(int i = 0 ; i <= 10 ; i ++)
m.push_back(i);
m.insert(m.begin()+1,20); // 在最开始的某位置前增加元素
m.erase(m.begin()+3); //删除在m.begin()后的元素即m[]
sort(m.begin(),m.end(),cmp);
reverse(m.begin(),m.end()); //翻转的函数
for(int i = 0; i <= m.size()-1 ; i++)
cout << m[i] << " ";
cout << endl;
return 0;
}
自己在写pair的时候感觉东西有点少
#include<iostream>
using namespace std;
int main()
{
pair<string,string> author("one","two"); //默认构造
pair<string,string> author1(author); //拷贝构造
cout << author1.first << " " << author1.second << endl;
string f,s;
cin >> f >> s;
author = make_pair(f,s); // make_up的使用
cout << author.first << " " << author.second << endl;
return 0;
}
map的部分.
标签:
原文地址:http://www.cnblogs.com/00-00/p/4338269.html