C++ error: "Array must be initialized with a brace enclosed initializer" -
i getting following c++ error:
array must initialized brace enclosed initializer
from line of c++
int cipher[array_size][array_size];
what problem here? error mean? below full code:
string decryption(string todecrypt) { int cipher[array_size][array_size] = 0; string ciphercode = todecrypt.substr(0,3); todecrypt.erase(0,3); decodecipher(ciphercode,cipher); string decrypted = ""; while(todecrypt.length()>0) { string unit_decrypt = todecrypt.substr(0,array_size); todecrypt.erase(0,array_size); int tomultiply[array_size]=0; for(int = 0; < array_size; i++) { tomultiply[i] = int(unit_encrypt.substr(0,1)); unit_encrypt.erase(0,1); } for(int = 0; < array_size; i++) { int resultchar = 0; for(int j = 0; j<array_size; j++) { resultchar += tomultiply[j]*cipher[i][j]; } decrypted += char((resultchar%229)-26); } } return decrypted; }
the syntax statically initialize array uses curly braces, this:
int array[10] = { 0 };
this zero-initialize array.
for multi-dimensional arrays, need nested curly braces, this:
int cipher[array_size][array_size]= { { 0 } };
note array_size
must compile-time constant work. if array_size
not known @ compile-time, must use dynamic initialization. (preferably, std::vector
).
Comments
Post a Comment