Created
August 28, 2016 04:57
-
-
Save bg1bgst333/0809f4acf0d889a460408339614b926b to your computer and use it in GitHub Desktop.
vector#vector
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ヘッダのインクルード | |
#include <iostream> // C++標準入出力 | |
#include <vector> // 動的配列 | |
// main関数の定義 | |
int main(){ | |
// オブジェクトの宣言 | |
std::vector<int> vec; // std::vectorオブジェクトvec(int型要素) | |
// 追加 | |
vec.push_back(0); // vec.push_backで0を追加. | |
vec.push_back(10); // vec.push_backで10を追加. | |
vec.push_back(20); // vec.push_backで20を追加. | |
// すべての要素を取得し, 出力. | |
for (int i = 0; i < vec.size(); i++){ // int型iは0からvec.size(vecの要素数)に満たない間まで繰り返す. | |
// i番目の要素を取得し, 出力. | |
std::cout << "vec[" << i << "] = " << vec[i] << std::endl; // vec[i]でi番目を取得できるので, それをそのまま出力. | |
} | |
// プログラムの終了 | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment