⼆维数组的初始化(⼆维数组的赋值)⼆维数组的初始化必须在声明的时候进⾏。否则会报错。
⽐如,你应该在声明它的时候就⽴即赋值:
unsigned char bitmap[16][17]={{0,0,0,0,0,0,0,0,0,0,255,255,255,255,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0},
{255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,255,255,255,255,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0},
{0,0,0,0,0,0,0,0,255,255,255,255,255,255,0,0,0},
{0,0,0,0,0,0,0,0,0,0,255,255,255,255,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,255,255,0,0,0},
{0,0,255,255,255,0,0,0,0,255,255,255,255,255,255,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,255,255,0,0,0},
{0,0,0,0,0,0,0,0,0,255,255,255,255,255,0,0,0},
{0,0,0,255,255,0,0,0,0,0,255,255,255,255,0,0,0},
{0,0,0,0,0,255,0,0,0,0,255,255,255,255,0,0,0},
{255,255,255,255,255,0,0,0,0,0,255,255,255,255,0,0,0}};
如果改成这样就会报错:怎么给数组赋值
unsigned char bitmap[16][17];
bitmap[16][17]={{0,0,0,0,0,0,0,0,0,0,255,255,255,255,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0},
{255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,255,255,255,255,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,255,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,255,255,255,0,0,0},
{0,0,0,0,0,0,0,0,255,255,255,255,255,255,0,0,0},
{0,0,0,0,0,0,0,0,0,0,255,255,255,255,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,255,255,0,0,0},
{0,0,255,255,255,0,0,0,0,255,255,255,255,255,255,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,255,255,0,0,0},
{0,0,0,0,0,0,0,0,0,255,255,255,255,255,0,0,0},
{0,0,0,255,255,0,0,0,0,0,255,255,255,255,0,0,0},
{0,0,0,0,0,255,0,0,0,0,255,255,255,255,0,0,0},
{255,255,255,255,255,0,0,0,0,0,255,255,255,255,0,0,0}};
报错:
1>d:\vs_pro\mark_region\span_ccl\main.cpp(23) : error C2059: syntax error : '{'
1>d:\vs_pro\mark_region\span_ccl\main.cpp(23) : error C2143: syntax error : missing ';' before '{' 1>d:\vs_pro\mark_region\span_ccl\main.cpp(23) : error C2143: syntax error : missing ';' before '}'
⽽且你很难出出错的原因。
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论