CPP_vectorの使い方 のバックアップ差分(No.1) - アールメカブ

アールメカブ


CPP_vectorの使い方 のバックアップ差分(No.1)


  • 追加された行はこの色です。
  • 削除された行はこの色です。
 [[Programming]]

 #include <iostream>
 #include <vector>
 //#include <list>

 using namespace std;
 //vector<int> v;

 void myadd(std::vector<int> &v, int x){
              //void myadd(int x){
  v.push_back(x);
            //v.push_end(x);
 }
 
 int main(){
 
  vector<int> v;
 for(int i = 0; i < 5; i++)
     v.push_back(i);
 
 int x = 6;
 
 vector<int>::iterator pv = v.begin();
 
 while(pv != v.end()){
   cout << *pv++ << ' ';
   if(x < 10){
     //cout << x << " in first loop" << endl;
     myadd(v,x++);
     // myadd(x++);
   }
 }
 cout << endl;
  
 while(pv != v.end()){
   cout << *pv++ << ' ';
   if(x < 10){
     cout << x << " in second loop" << endl;
   }
 }
    
 return 0;
 }