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;
}