1 次元配列

/****************************/
/* 1 次元配列               */
/*      coded by Y.Suganuma */
/****************************/
#include <iostream>
#include <vector>
#include <array>

using namespace std;

int main()
{
				// vector クラス
	cout << "vector クラス\n";
	vector<int> a1 = {1, 2, 3};
	cout << "   a1: " << a1[0] << " " << a1[1] << " " << a1[2] << endl;
	a1.push_back(4);   // 要素の追加
	vector<int>::iterator it = a1.begin();
	it++;
	a1.erase(it);   // 2 番目の要素を削除
	cout << "   追加と削除 a1: " << a1[0] << " " << a1[1] << " " << a1[2] << endl;
				// array クラス
	cout << "array クラス\n";
	array<int, 3> b1 = {1, 2, 3};
	cout << "   b1: " << b1[0] << " " << b1[1] << " " << b1[2] << endl;
				// 配列
	cout << "配列\n";
	int c1[] = {1, 2, 3};
	cout << "   c1: " << c1[0] << " " << c1[1] << " " << c1[2] << endl;
				// 配列(new 演算子)
	cout << "配列(new 演算子)\n";
	int *d1 = new int [3] {1, 2, 3};
	cout << "   d1: " << d1[0] << " " << d1[1] << " " << d1[2] << endl;

	return 0;
}
		
(出力)
vector クラス
   a1: 1 2 3
   追加と削除 a1: 1 3 4
array クラス
   b1: 1 2 3
配列
   c1: 1 2 3
配列(new 演算子)
   d1: 1 2 3