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