我声明了一个向量并尝试放置大小和值并打印它
#include<iostream>
#include<vector>
using namespace std;
int main()
{
int s;
cin>>s; //taking size of vector
vector <int> arr(s);
int input;
while (cin >> input)
{arr.push_back(input);} //inserting the values in array
for(int i=0;i<s;i++)
cout<<" "<<arr[i]; //printing the values
}
Run Code Online (Sandbox Code Playgroud)
我的输入 5
1 2 3 4 5
预期输出
1 2 3 4 5
电流输出 0 0 0 0 0