c++声明字节数组时出现语法错误
我试图声明一个字节数组,以便我可以遍历它们并单独使用它们中的每一个。这是数组
const BYTE keybyte[] = {
0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50,
0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57 0x58,
0x59, 0x5A, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35,
0x36, 0x37, 0x38, 0x39, 0x25, 0x27, 0x26, 0x28,
0x0D, 0x20, 0x10, 0x11, 0x12, 0x18};
出于某种原因,当我编译时,它给了我这些错误:/
error C2143: syntax error : missing '}' before 'constant'
error C2143: syntax error : missing ';' before 'constant'
error C2059: syntax error : 'constant'
error C2143: syntax error : missing ';' before '}'
error C2059: syntax error : '}'
我不明白,因为如果我用
const BYTE keybyte[] = {0,0,0,0};
它替换它,它就可以完美地工作,没有错误:/?
Im trying to declare an array of bytes so I can go through them and use each one of them seperatly. This is the array
const BYTE keybyte[] = {
0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50,
0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57 0x58,
0x59, 0x5A, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35,
0x36, 0x37, 0x38, 0x39, 0x25, 0x27, 0x26, 0x28,
0x0D, 0x20, 0x10, 0x11, 0x12, 0x18};
For some reason when I compile it gives me these errors :/
error C2143: syntax error : missing '}' before 'constant'
error C2143: syntax error : missing ';' before 'constant'
error C2059: syntax error : 'constant'
error C2143: syntax error : missing ';' before '}'
error C2059: syntax error : '}'
I dont understand because if I replace it with
const BYTE keybyte[] = {0,0,0,0};
it works perfectly fine with no errors :/?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
0x57
和0x58
之间缺少逗号。You are missing a comma between
0x57
and0x58
.亚历山大·盖斯勒是对的——缺少逗号。下次尝试使用 gcc 和 clang 编译文件。它将引导您解决问题:
对于文件 test.h 包含:
当我尝试 GCC 时:
编译器解析器说,第 1 行和字符 42 上的语法错误:
当我询问 clang 时,我得到更好的输出:
所以我看看问题出在哪里。
Alexander Gessler is right - comma is missing. Next Time try compile file with gcc and clang. It will guide you to problem resolution:
For file test.h containing:
when I try GCC:
Compilers parser says, the syntax is wrong on the line 1 and the character 42:
When I ask clang, I get even better output:
so I see where the problem is.