33.向vector里面添加数字,换行敲下输入结束

版权声明:本博客为记录本人学习过程而开,内容大多从网上学习与整理所得,若侵权请告知! https://blog.csdn.net/Fly_as_tadpole/article/details/83021430

向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循环这一块

猜你喜欢

转载自blog.csdn.net/Fly_as_tadpole/article/details/83021430