1. 程式人生 > >33.向vector裡面新增數字,換行敲下輸入結束

33.向vector裡面新增數字,換行敲下輸入結束

向vector裡面新增數字,換行敲下輸入結束

#include <iostream>
#include<vector>
using namespace std;
int main()
{
	vector<int>tmp;
	int num;
	while (cin >> num)
	{
		tmp.push_back(num);
		if (cin.get() == '\n')
			break;
	}

	for (int j = 0; j < tmp.size(); j++)
	{
		cout << tmp[j] << endl;
	}


	system("pause");
	return 0;
}

注意判斷條件,即while迴圈這一塊