C++ error: “Array must be initialized with a brace enclosed initializer”

前端 未结 3 956
天涯浪人
天涯浪人 2020-12-09 16:37

I am getting the following C++ error:

array must be initialized with a brace enclosed initializer 

From this line of C++

in         


        
3条回答
  •  爱一瞬间的悲伤
    2020-12-09 16:52

    You cannot initialize an array to '0' like that

    int cipher[Array_size][Array_size]=0;
    

    You can either initialize all the values in the array as you declare it like this:

    // When using different values
    int a[3] = {10,20,30};
    
    // When using the same value for all members
    int a[3] = {0};
    
    // When using same value for all members in a 2D array
    int a[Array_size][Array_size] = { { 0 } };
    

    Or you need to initialize the values after declaration. If you want to initialize all values to 0 for example, you could do something like:

    for (int i = 0; i < Array_size; i++ ) {
        a[i] = 0;
    }
    

提交回复
热议问题