C++ : Creating an array with a size entered by the user

后端 未结 3 572
不知归路
不知归路 2020-12-01 20:36

I was wondering if we can make an array with a size specified by the user.

Ex:

int a;
cout<<\"Enter desired size of the array\";
cin>>a;
         


        
3条回答
  •  隐瞒了意图╮
    2020-12-01 20:38

    Use std::vector (requires header ):

    int size;
    cout<<"Enter desired size of the array";
    cin >> size;
    std::vector array(size);
    

提交回复
热议问题