#include <iostream>
#include <vector>
using namespace std;
class test{
private:
int i;
public :
test(){}
~test(){}
public :
void input(int i){
this -> i = i;
}
void output(){
cout << i << "\n";
}
int getNum(){
return i;
}
};
int main(){
vector<test> *vec = new vector<test>;
int num =0;
int v_num =0;
cout << "生成するvectorの数---"; cin >> v_num;
for(int i=0; i<v_num; i++){
test t;
t.input(num);
vec -> push_back(t);
num +=50;
}
/* vectorの要素を削除する */
vector<test>::iterator it = vec->begin();
it +=2;
it = vec->erase(it);
for(int i = 0;
i < vec->size();
i++)
{
test t = (test)vec->at(i);
t.output();
}
for(int i = 0;
i < vec->size();
i++)
{
test t = (test)vec->at(i);
if(t.getNum() == 150)
cout << "一致しました\n";
if(t.getNum() == 100) // i=100は削除済みなので実行されない:42
cout << "一致しました\n";
}
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCgpjbGFzcyB0ZXN0ewoJcHJpdmF0ZToKCQlpbnQgaTsKCQoJcHVibGljIDoKCQkgdGVzdCgpe30KCQl+dGVzdCgpe30KCXB1YmxpYyA6CgkJdm9pZCBpbnB1dChpbnQgaSl7CgkJCXRoaXMgLT4gaSA9IGk7CgkJfQoJCXZvaWQgb3V0cHV0KCl7CgkJCWNvdXQgPDwgaSA8PCAiXG4iOwoJCX0KCQlpbnQgZ2V0TnVtKCl7CgkJCXJldHVybiBpOwoJCX0KfTsKCmludCBtYWluKCl7Cgl2ZWN0b3I8dGVzdD4gKnZlYyA9IG5ldyB2ZWN0b3I8dGVzdD47CgkKCWludCBudW0gPTA7CgkKCWludCB2X251bSA9MDsKCWNvdXQgPDwgIueUn+aIkOOBmeOCi3ZlY3RvcuOBruaVsC0tLSI7CWNpbiA+PiB2X251bTsKCWZvcihpbnQgaT0wOyBpPHZfbnVtOyBpKyspewoJCXRlc3QgdDsKCQl0LmlucHV0KG51bSk7CgkJCgkJdmVjIC0+IHB1c2hfYmFjay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