C++中的语法错误
syntax errors in C++
我是c++的新手。我的朋友刚刚给了我这个代码,但它不起作用,并发送了许多语法错误,如:错误C2146,错误C2734,。。。我不熟悉,所以我认为最好询问堆栈溢出。pixel.cpp:
#include<iostream>
#include"a.h"
using namespace std;
extern const unsigned uint_8 microsoftSansSerif_8ptBitmaps[];
extern const unsigned FONT_INFO microsoftSansSerif_8ptFontInfo;
extern const FONT_CHAR_INFO microsoftSansSerif_8ptDescriptors[];
int main()
{
getchar();
}
a.h:
// Font data for Microsoft Sans Serif 8pt
const unsigned uint_8 microsoftSansSerif_8ptBitmaps[] = {
0b11110000,
0b00010000,
0b00101000,
0b00101000,
0b01000100,
0b01000100,
0b01111100,
0b10000010,
0b10000010,
};
const FONT_CHAR_INFO microsoftSansSerif_8ptDescriptors[] =
{
{7, 0}, // A
};
const FONT_INFO microsoftSansSerif_8ptFontInfo =
{
2, // Character height
'A', // Start character
'A', // End character
2, // Width, in pixels, of space character
microsoftSansSerif_8ptDescriptors, // Character descriptor array
microsoftSansSerif_8ptBitmaps, // Character bitmap array
};
错误:
a.h(2) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
a.h(2) : error C2146: syntax error : missing ';' before identifier 'microsoftSansSerif_8ptBitmaps'
a.h(3) : error C2059: syntax error : 'bad suffix on number'
a.h(3) : error C2146: syntax error : missing '}' before identifier 'b11110000'
a.h(4) : error C2059: syntax error : 'constant'
一些问题:
-
uint_8
、FONT_INFO
和FONT_CHAR_INFO
不在任何地方声明。 -
在自定义类型之前不必要地添加
unsigned
是错误的。 -
二进制文字需要在c++11模式下编译,以及支持该模式的编译器。
-
要使用
getchar
,需要包含<cstdio>
。 -
通常,应该将
extern
声明放在.h
文件中,将定义放在.cpp
中,而不是相反。
相关文章:
- 为什么包含windows.h会产生语法错误,从而阻止类的实例化?(C2146,C2065)
- 错误 C2760:语法错误:映射迭代器上意外的标记"标识符",预期的";"
- 为什么我会收到错误 C2143 语法错误:缺少"*"之前的';'?
- 奇怪的代码抛出编译错误模板< J,int aSize=10> C2143:语法错误:在"<"之前缺少";"
- "错误 C0000:语法错误,令牌"<EOF>"处出现意外$end,并且不确定
- 我该怎么做才能摆脱使用命名空间时的语法错误?
- C++语法头文件错误
- 如何摆脱错误c2061;语法错误 cout?
- 语法错误:D3DX10Core 中的标识符'TEXTMETRICA'
- 错误 C2146:语法错误:标识符"A1"之前缺少","
- main.cpp(11):错误 C2059:语法错误:"字符串"
- 我想获取点的属性,它报告错误 C3867:"point::output_x":非标准语法;使用"&"创建指向成员的指针
- RedisGraph 语法错误在偏移量 8 靠近"创建"
- 如何修复此 FSM C++语法错误 C3867
- 函数错误 C2059:语法错误:'>'不起作用
- 为什么在main()之前断言会导致语法错误"error: expected ')' before numeric constant"?
- system() 返回错误语法错误:"("意外
- C++图形初始化错误(语法或丢失文件缺陷?
- 获取0:1(1):错误:语法错误,尝试编译着色器时意外$end
- Visual Studio错误:语法错误:标识符