- 此问题在此处已有答案**:
Initialize multidimensional array with zeros(7个答案)
Expression does not evaluate to a constant(1个答案)
Variable Length Array (VLA) in C++ compilers(2个答案)
Why aren't variable-length arrays part of the C++ standard?(10个答案)
4天前关闭。
我尝试将2D数组(矩阵)初始化为0,但无法执行:
int longestCommonSubsequence(string text1, string text2) {
int len1=0;
len1=text1.length()+1;
int len2=0;
len2=text2.length()+1;
int dp[len1][len2]={0};
错误:
Line 8: Char 16: error: variable-sized object may not be initialized
int dp[len1][len2]={0};
^~~~
1 error generated.
我想在声明矩阵时初始化它。我不想使用for循环。
1条答案
按热度按时间gg58donl1#
可变长度的数组不是标准的C++,对于定长数组,你只需使用值初始化语法:
或者,使用可变长度的C++集合: