STL Samples : <vector>
可変長配列
vector
#include <iostream> #include <vector> #include "to_string.h" #include "foo.h" using namespace std; void std_vector() { cout << "vector" << endl; vector<Foo> vf(5); for ( int i = 0; i < 5; i++ ) vf[i] = i; cout << to_string(vf.begin(), vf.end()) << endl; while ( !vf.empty() ) { cout << "remove last element: " << vf.back(); vf.pop_back(); cout << ": " << to_string(vf.begin(), vf.end()) << endl; } }