- #include <vector>
- #include <iostream>
- using namespace std;
- struct xy{
- public:
- int x,y;
- xy(int _x, int _y):x(_x),y(_y){}
- };
- int main(){
- vector<xy> v,w;
- //either you reserve and then assign values
- v.reserve(1);
- v[0]=xy(1,2); //would crash if you don't reserve
- cout<<v[0].x<<" "<<v[0].y<<endl;
- //or you just push_back
- w.push_back(xy(1,2));
- cout<<v[1].x<<" "<<v[1].y<<endl;
- system("pause");
- return 0;
- }