Pabon_SEC

Vector

Oct 7th, 2015
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.57 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3.  
  4. using namespace std;
  5.  
  6. vector<int>vec1,vec3;
  7. vector<int>vec2[100];
  8.  
  9. vector<string>str;
  10.  
  11. int main()
  12. {
  13.     int k=0;
  14.     while(k<2)
  15.     {
  16.         string s="Pabon",s1="Toufiq",s2="Shawon",s3="Bidhan";
  17.  
  18.         vec1.push_back(1);
  19.         vec1.push_back(2);
  20.         vec1.push_back(3);
  21.         vec1.push_back(4);
  22.  
  23.         vec3=vec1;
  24.         cout<<"\nPrint 1D array\n\n";
  25.  
  26.         for(int i=0; i<vec1.size(); i++)
  27.         {
  28.             cout<<" "<<vec1[i];
  29.         }
  30.  
  31.         cout<<"\n";
  32.  
  33.         vec1.pop_back();
  34.  
  35.         for(int i=0; i<vec1.size(); i++)
  36.         {
  37.             cout<<" "<<vec1[i];
  38.         }
  39.  
  40.         cout<<"\n";
  41.  
  42.         vec2[0].push_back(4);
  43.         vec2[0].push_back(5);
  44.         vec2[0].push_back(6);
  45.  
  46.         vec2[1].push_back(9);
  47.         vec2[1].push_back(10);
  48.  
  49.         vec2[2].push_back(11);
  50.  
  51.         cout<<"\nPrint 2D array\n\n";
  52.  
  53.         for(int i=0; i<3; i++)
  54.         {
  55.             for(int j=0; j<vec2[i].size(); j++)
  56.             {
  57.                 cout<<" "<<vec2[i][j];
  58.             }
  59.             cout<<endl;
  60.         }
  61.  
  62.         cout<<"\nPrint string\n\n";
  63.  
  64.         str.push_back(s);
  65.         str.push_back(s1);
  66.         str.push_back(s2);
  67.         str.push_back(s3);
  68.  
  69.         for(int i=0; i<str.size(); i++)
  70.         {
  71.             cout<<str[i]<<endl;
  72.         }
  73.  
  74.         vec1.clear();
  75.         vec2[0].clear();
  76.         vec2[1].clear();
  77.         vec2[2].clear();
  78.         vec3.clear();
  79.         str.clear();
  80.  
  81.         k++;
  82.  
  83.         cout<<"\n\n----------\n\n";
  84.  
  85.     }
  86.  
  87.     return 0;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment