我正在创建一个函数,它将获取一个char参数并将其转换为bool [8] [8]数组。这就是我现在的功能:
void DotMatrix::displayCharacter(char c, bool doScrolling, int milliseconds){
bool pixelMap[8][8];
if (c == 'A'){
pixelMap = {
{0,0,1,1,1,0,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0},
{0,1,1,1,1,1,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0}
};
} else if (c == 'B'){
pixelMap = {
{0,1,1,1,1,0,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0},
{0,1,1,1,1,0,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0},
{0,1,1,1,1,0,0,0}
};
} else if (c == 'C'){
pixelMap = {
{0,0,0,1,1,0,0,0},
{0,0,1,0,0,1,0,0},
{0,1,0,0,0,0,0,0},
{0,1,0,0,0,0,0,0},
{0,1,0,0,0,0,0,0},
{0,1,0,0,0,0,0,0},
{0,0,1,0,0,1,0,0},
{0,0,0,1,1,0,0,0}
};
} else if (c == 'D'){
pixelMap = {
{0,1,1,1,0,0,0,0},
{0,1,0,0,1,0,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,0,1,0,0,0},
{0,1,1,1,0,0,0,0}
};
} else if (c == 'E'){
pixelMap = {
{0,1,1,1,1,1,0,0},
{0,1,0,0,0,0,0,0},
{0,1,0,0,0,0,0,0},
{0,1,1,1,1,0,0,0},
{0,1,0,0,0,0,0,0},
{0,1,0,0,0,0,0,0},
{0,1,0,0,0,0,0,0},
{0,1,1,1,1,1,0,0}
};
} else if (c == 'F'){
pixelMap = {
{0,1,1,1,1,1,0,0},
{0,1,0,0,0,0,0,0},
{0,1,0,0,0,0,0,0},
{0,1,1,1,1,0,0,0},
{0,1,0,0,0,0,0,0},
{0,1,0,0,0,0,0,0},
{0,1,0,0,0,0,0,0},
{0,1,0,0,0,0,0,0}
};
} else if (c == 'G'){
pixelMap = {
{0,0,1,1,1,0,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,0,0,0},
{0,1,0,0,0,0,0,0},
{0,1,0,0,0,0,0,0},
{0,1,0,0,1,1,0,0},
{0,1,0,0,0,1,0,0},
{0,0,1,1,1,0,0,0}
};
} else if (c == 'H'){
pixelMap = {
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0},
{0,1,1,1,1,1,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0}
};
} else if (c == 'I'){
pixelMap = {
{0,1,1,1,1,1,0,0},
{0,0,0,1,0,0,0,0},
{0,0,0,1,0,0,0,0},
{0,0,0,1,0,0,0,0},
{0,0,0,1,0,0,0,0},
{0,0,0,1,0,0,0,0},
{0,0,0,1,0,0,0,0},
{0,1,1,1,1,1,0,0}
};
} else if (c == 'J'){
pixelMap = {
{0,0,0,0,1,1,0,0},
{0,0,0,0,0,1,0,0},
{0,0,0,0,0,1,0,0},
{0,0,0,0,0,1,0,0},
{0,0,0,0,0,1,0,0},
{0,0,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0},
{0,0,1,1,1,0,0,0}
};
} else if (c == 'K'){
pixelMap = {
{0,1,0,0,0,1,0,0},
{0,1,0,0,1,0,0,0},
{0,1,0,1,0,0,0,0},
{0,1,1,0,0,0,0,0},
{0,1,0,1,0,0,0,0},
{0,1,0,0,1,0,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0}
};
} else if (c == 'L'){
pixelMap = {
{0,1,0,0,0,0,0,0},
{0,1,0,0,0,0,0,0},
{0,1,0,0,0,0,0,0},
{0,1,0,0,0,0,0,0},
{0,1,0,0,0,0,0,0},
{0,1,0,0,0,0,0,0},
{0,1,0,0,0,0,0,0},
{0,1,1,1,1,1,0,0}
};
} else if (c == 'M'){
pixelMap = {
{0,1,1,0,1,1,0,0},
{0,1,0,1,0,1,0,0},
{0,1,0,1,0,1,0,0},
{0,1,0,1,0,1,0,0},
{0,1,0,1,0,1,0,0},
{0,1,0,1,0,1,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0}
};
} else if (c == 'N'){
pixelMap = {
{0,1,0,0,0,1,0,0},
{0,1,1,0,0,1,0,0},
{0,1,1,0,0,1,0,0},
{0,1,0,1,0,1,0,0},
{0,1,0,1,0,1,0,0},
{0,1,0,0,1,1,0,0},
{0,1,0,0,1,1,0,0},
{0,1,0,0,0,1,0,0}
};
} else if (c == 'O'){
pixelMap = {
{0,0,1,1,1,0,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0},
{0,0,1,1,1,0,0,0}
};
} else if (c == 'P'){
pixelMap = {
{0,1,1,1,1,0,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0},
{0,1,1,1,1,0,0,0},
{0,1,0,0,0,0,0,0},
{0,1,0,0,0,0,0,0},
{0,1,0,0,0,0,0,0},
{0,1,0,0,0,0,0,0}
};
} else if (c == 'Q'){
pixelMap = {
{0,0,1,1,1,0,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,1,0,1,0,0},
{0,1,0,0,1,1,0,0},
{0,0,1,1,1,0,1,0}
};
} else if (c == 'R'){
pixelMap = {
{0,1,1,1,1,0,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0},
{0,1,1,1,1,0,0,0},
{0,1,0,1,0,0,0,0},
{0,1,0,0,1,0,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0}
};
} else if (c == 'S'){
pixelMap = {
{0,0,1,1,1,0,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,0,0,0},
{0,0,1,1,1,0,0,0},
{0,0,0,0,0,1,0,0},
{0,0,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0},
{0,0,1,1,1,0,0,0}
};
} else if (c == 'T'){
pixelMap = {
{0,1,1,1,1,1,0,0},
{0,0,0,1,0,0,0,0},
{0,0,0,1,0,0,0,0},
{0,0,0,1,0,0,0,0},
{0,0,0,1,0,0,0,0},
{0,0,0,1,0,0,0,0},
{0,0,0,1,0,0,0,0},
{0,0,0,1,0,0,0,0}
};
} else if (c == 'U'){
pixelMap = {
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0},
{0,0,1,1,1,1,0,0}
};
} else if (c == 'V'){
pixelMap = {
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0},
{0,0,1,0,1,0,0,0},
{0,0,1,0,1,0,0,0},
{0,0,1,0,1,0,0,0},
{0,0,0,1,0,0,0,0},
{0,0,0,1,0,0,0,0}
};
} else if (c == 'W'){
pixelMap = {
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,1,0,1,0,0},
{0,1,0,1,0,1,0,0},
{0,1,1,0,1,1,0,0}
};
} else if (c == 'X'){
pixelMap = {
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0},
{0,0,1,0,1,0,0,0},
{0,0,1,0,1,0,0,0},
{0,0,0,1,0,0,0,0},
{0,0,1,0,1,0,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0}
};
} else if (c == 'Y'){
pixelMap = {
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0},
{0,0,1,0,1,0,0,0},
{0,0,0,1,0,0,0,0},
{0,0,0,1,0,0,0,0},
{0,0,0,1,0,0,0,0},
{0,0,0,1,0,0,0,0},
{0,0,0,1,0,0,0,0}
};
} else if (c == 'Z'){
pixelMap = {
{0,1,1,1,1,1,0,0},
{0,0,0,0,0,1,0,0},
{0,0,0,0,1,0,0,0},
{0,0,0,1,0,0,0,0},
{0,0,0,1,0,0,0,0},
{0,0,1,0,0,0,0,0},
{0,1,0,0,0,0,0,0},
{0,1,1,1,1,1,0,0}
};
} else if (c == ' '){
pixelMap = {
{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,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,0,0}
};
}
if (doScrolling == 1){
scrollPixels(milliseconds, pixelMap);
} else {
displayPixels(milliseconds, pixelMap);
}
} 但是,当我在程序中运行此代码时,它返回:
error: assigning to an array from an initializer list
答案 0 :(得分:2)
考虑一个更好的方法:
SELECT a.* FROM table a, new_table b WHERE UPPER(a.col1) LIKE UPPER(b.col);
无需复制或指定任何内容。
答案 1 :(得分:0)
使用初始化列表时,无法在运行时为数组显式赋值。
试试这个:
auto tempMap = std::initializer_list<bool>({
{0,0,1,1,1,0,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0},
{0,1,1,1,1,1,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0},
{0,1,0,0,0,1,0,0});
std::copy(tempMap.begin(), tempMap.end(), pixelMap);
如果您最终要将其写入视频帧缓冲区,请考虑使用char而不是bool。这会简化一些事情,虽然你的代码看起来不那么漂亮;)