难点:C++ 在定义数组的时候,必须指定确定的长度,因此数组大小不能是变
int a;
int b[a]; //会报错
C++标准模板(STL)vecto可以实现动态数组意味着在添加元素时会自动调整其大小。
#include<iostream>
#include <vector>
using namespace std;
int main()
{
vector<int> v1;
int a;
while (cin>>a )
{
v1.push_back(a);
}
for(vector<int>::iterator itr = v1.begin(); itr != v1.end(); itr++)
{
cout << *itr << endl;
}
}