Created
August 5, 2014 08:35
-
-
Save chomado/34323840d2ba505cb55f to your computer and use it in GitHub Desktop.
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
// 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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
実行結果
整数を入力せよ
終了は9999
x[0] = 15
x[1] = 92
x[2] = 73
x[3] = 65