error C2065: “xxxx”: 未声明的标识符

xiaoxiao2021-02-28  11

  在编译代码的时候经常会出现error C2065: “xxxx”: 未声明的标识符,这个错误。一般情况下添加对应的头文件即可,但有的时候明明添加了对应的头文件,却还是报错,

下面是博主总结的几点修改经验:

1.改变引用头文件的顺序;include就是将包含文件机械插入到所在的位置,比如@caozhy举的例子

a.h中写 int add(int a, int b); b.h中写 void call() { add(1, 2); } c.h中写 int add(int a, int b) { return a + b; } 那么 #include "a.h" #include "b.h" #include "b.h" 可以编译 但是 #include "b.h" #include "a.h" #include "c.h" 显然就不行了 另外@passion_wu128总结的系统文件在最前面,然后是第三方库文件,最后是自己的头文件。

2.添加 using namespace std; string对于编译器来说是个名字,这个名字在std名称空间中,如果你不在string这个名字出现之前添加std声明,编译器就不知道它是什么东西.

3.检查拼写错误;这个就不解释了。

转载请注明原文地址: https://www.6miu.com/read-200113.html

最新回复(0)