[英]Braces around scalar initializer error in C++
我試圖為數字制作一個簡單的“字體”,以便通過Arduino在我的8x8顯示器上使用。 這只是一個簡單的測試。
#include <iostream>
using namespace std;
class Font{
public:
void Number(int num){
switch(num){
case 0:
bool Font[][5] = {{{{ 0, 1, 0,
1, 0, 1,
1, 0, 1,
1, 0, 1,
0, 1, 0 }}}};
break;
for(int y = 0; y < 5; y++){
for(int x = 0; x < 3; x++){
cout << Font[y][x];
}
cout << endl;
}
}
}
};
int main()
{
Font myFont;
myFont.Number(0);
return 0;
}
但是,當我運行此命令時,出現錯誤消息“ 13:34:錯誤:類型'bool'0,1,0}}}}};的標量初始化程序大括號”;
這不是您初始化多維數組的方式。 您可以使用
bool Font[][5] = {{ 0, 1, 0 },
{ 1, 0, 1 },
{ 1, 0, 1 },
{ 1, 0, 1 },
{ 0, 1, 0 }};
要么
bool Font[][5] = {0, 1, 0,
1, 0, 1,
1, 0, 1,
1, 0, 1,
0, 1, 0};
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.