下書きのまま残ってたので放出:
勉強中。
// JavaScript
var arr = [];
arr.push(101);
arr.push(-1);
arr.push(999);
for (var i=0, l=arr.length; i<l; i++) {
var n = arr[i];
console.log(i, n);
}
// C++
#include <vector>
std::vector<int> arr;
arr.push_back(101);
arr.push_back(-1);
arr.push_back(999);
for (int i=0, l=arr.size(); i<l; i++) {
int n = arr[i];
printf("%d, %d\n", i, n);
}
push_back()
の逆はpop_back()
だが、これは末尾を削除するだけで、値を返さない。(戻り値はvoid
。) "_back"て何だろう?
参考: