arpit728

vector in STL

Jan 16th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.35 KB | None | 0 0
  1. //Example of vector using pushback
  2.  
  3. #include<vector>
  4. #include<iostream>
  5.  
  6. using namespace std;
  7.  
  8. int main(){
  9.  
  10. vector<int>v(5);
  11.  
  12. for(int i=0;i<10;i++){
  13.  
  14. //v[i]=i+1;
  15. v.push_back(i+1);
  16. }
  17.  
  18. for(int i=0;i<10;i++){
  19. cout<<v[i]<<" ";
  20. }
  21.  
  22. cout<<endl;
  23.  
  24. cout<<"There are "<<v.size()<<" elements in your vector"<<endl;
  25.  
  26. return 0;
  27. }
Add Comment
Please, Sign In to add comment