小编BAT*_*N_X的帖子

我要求用户输入大小和数组,但是当我打印矢量时,它仅显示“0”作为输出

我声明了一个向量并尝试放置大小和值并打印它

#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

c++ vector while-loop

1
推荐指数
1
解决办法
81
查看次数

标签 统计

c++ ×1

vector ×1

while-loop ×1