やったこと
vector を使ってみます。
確認環境
$ g++ --version
g++ (Homebrew GCC 9.2.0) 9.2.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
調査
test.cpp
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> v { 20, 30, 50 };
v.push_back(90);
v[0] = 1;
for (int v2: v) {
printf("%d\n", v2);
}
printf("---\n");
for (vector<int>::iterator it = v.begin(); it != v.end(); it++) {
printf("%d\n", *it);
}
}
出力結果
1
30
50
90
---
1
30
50
90