Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Sep 27th, 2012  |  syntax: None  |  size: 0.48 KB  |  hits: 33  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include <vector>
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. struct xy{
  6. public:
  7.     int x,y;
  8.     xy(int _x, int _y):x(_x),y(_y){}
  9. };
  10.        
  11. int main(){
  12.     vector<xy> v,w;
  13.    
  14.     //either you reserve and then assign values
  15.     v.reserve(1);
  16.     v[0]=xy(1,2); //would crash if you don't reserve
  17.     cout<<v[0].x<<" "<<v[0].y<<endl;
  18.  
  19.     //or you just push_back
  20.     w.push_back(xy(1,2));
  21.     cout<<v[1].x<<" "<<v[1].y<<endl;
  22.    
  23.     system("pause");
  24.     return 0;
  25. }