Home > Back-end >  Using vector. For the first try change the length of the array size function
Using vector. For the first try change the length of the array size function

Time:10-24

 # include 
# include
# include
# include
# include
# include
using namespace std;

Int main () {
Const int sz=10;
Vector Ivec;
Srand ((unsigned) time (NULL));
For (int I=0; The I!=sz; I++)
{
Ivec. Push_back (rand () % 100);
Cout & lt; };
//const int b=ivec. The size ();

Auto b=ivec. The size ();
Int a [b];
}






Error problem not solve, b is const int type, Daniel glad, thank you very much

CodePudding user response:

C + + array must be able to in the compiler to determine the amount of const, running period are not determined
C99 only can use the dynamic array, but can't use the STL c

CodePudding user response:

Since the size of the b is unknown, you can write int a [sz] can also write a=new int * int [b]
  • Related