#include<iostream> #include<cstdio> #include<vector> #include<algorithm> using namespace std; vector<int> a; vector<int> b[100]; int main() { a.push_back(1); a.push_back(2); cout<<a[0]<<" "<<a[1]<<endl; cout<<a.front()<<" "<<a.back()<<endl; a.push_back(0); sort(a.begin(),a.end()); for (int i=0;i<a.size();i++) cout<<a[i]<<" "; cout<<endl; a.pop_back(); cout<<a[1]; a.empty(); //vector是否为空 a.clear(); //清空vector return 0; }
发现一个大佬写的Vector一些更骚的用法:https://www.cnblogs.com/zwfymqz/p/7788554.html