#include #include //可変長配列 using namespace std; const int PLAYER_NUM{ 10 }; class samp { int n_;//<-プライベート public: samp() :n_(0) {} samp(int _n):n_(_n){} ~samp(){} void SetN(int _n) { n_ = _n; } int GetN() { return(n_); } }; int main() { //int arr[PLAYER_NUM]{ 2,4,6,8,10,12,14,16,18,20 }; //int num; //cin >> num; //int *player; //player = new int[num]; //for (int i = 0; i < num; i++) // player[i] = i + 1; //cout << "固定長配列" << endl; //for (int i = 0; i < PLAYER_NUM; i++) // cout << arr[i] << " "; // //cout << endl; //cout << "動的配列取得" << endl; //for (int i = 0; i < num; i++) // cout << player[i] << " "; //delete[] player; //samp Samp[PLAYER_NUM]{ 2,4,6,8,10,12,14,16,18,20 }; //for (int i = 0; i < PLAYER_NUM; i++) // cout << Samp[i].GetN() << " "; ////オブジェクトの動的取得でオブジェクト数を決める! //int num; //cin >> num; //int* initList = new int[num]; //for (int i = 0; i < num; i++) { // cout << i << "番目の値:"; // cin >> initList[i]; //} //samp* sampList = nullptr; //sampList = new samp[num]; //sampList[0]~sampList[num-1]までが生成される //for (int i = 0; i < num; i++) // sampList[i].SetN(initList[i]); //for (int i = 0; i < num; i++) // cout << sampList[i].GetN() << " "; vector sampList; int n = 0; while (true) { cout << "ただ今のsampListの長さ:" << sampList.size() << endl; cin >> n; if (n != -1) { samp* p = new samp(n); sampList.push_back(p); } else break; } //sampListの中身のsmapのn_を全部表示 for (auto theI : sampList) { cout << theI->GetN() << " "; } for (auto theI : sampList) delete theI; cout << "ただ今のsampListの長さ:" << sampList.size() << endl; sampList.clear(); cout << "ただ今のsampListの長さ:" << sampList.size() << endl; return 0; }