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

Untitled

By: a guest on Jun 27th, 2012  |  syntax: None  |  size: 0.42 KB  |  hits: 5  |  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. push_back a struct into a vector
  2. struct point{
  3.      int x;
  4.      int y;
  5. };
  6.  
  7. vector <point> a;
  8.  
  9. a.push_back( ??? );
  10.        
  11. point mypoint = {0, 1};
  12. a.push_back(mypoint);
  13.        
  14. a.push_back(point(0,1));
  15.        
  16. point make_point(int x, int y) {
  17.     point mypoint = {x, y};
  18.     return mypoint;
  19. }
  20.  
  21. a.push_back(make_point(0, 1));
  22.        
  23. point p;
  24. p.x = 1;
  25. p.y = 2;
  26.  
  27. a.push_back(p);
  28.        
  29. point foo; //initialize with whatever
  30. a.push_back(foo);