Skip to content

Instantly share code, notes, and snippets.

@chomado
Created August 5, 2014 08:35
Show Gist options
  • Save chomado/34323840d2ba505cb55f to your computer and use it in GitHub Desktop.
Save chomado/34323840d2ba505cb55f to your computer and use it in GitHub Desktop.
vector練習写経
// vector (事前に個数のわからないデータの読み込み)
#include <vector>
#include <iostream>
using namespace std;
int main()
{
vector<int> x;
cout << "整数を入力せよ \n 終了は9999" << endl;
while (true) {
int temp;
cin >> temp;
if (temp == 9999) break;
x.push_back(temp); // xの末尾にtempを追加
}
for (vector<int>::size_type i = 0; i < x.size(); i++)
cout << "x[" << i << "] = " << x[i] << endl;
}
@chomado
Copy link
Author

chomado commented Aug 5, 2014

実行結果

整数を入力せよ
終了は9999
x[0] = 15
x[1] = 92
x[2] = 73
x[3] = 65

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment