C/C++一些常见的错误
文章目录
- 1.comparison between pointer and integer :
- 2.error: 'for' loop initial declarations are only allowed in C99 mode
- 3.[Error] a function-definition is not allowed here before '{' token
- 4.[Error] 'f' was not declared in this scope
- 5.error C2679
- 6.Runtime Error
- 7.[Error] cannot convert 'int (\*)[4]' to 'char (\*)[4]' for argument '1' to 'void row(char (*)[4], int)'
- 8.[Error] ld returned 1 exit status
- 9.[Error] expected constructor, destructor, or type conversion before '(' token
- 10.[Error] 'pair' does not name a type
- 11.[Error] '>>' should be '> >' within a nested template argument list
- 12. [Warning] overflow in implicit constant conversion [-Woverflow]
- 13.[Error] a function-definition is not allowed here before '{' token
- 14.[Error] reference to 'map' is ambiguous
- 15.[Error] declaration of 'int x [3]' shadows a parameter
- 16.[Error] invalid types 'int[int]' for array subscript
- [Error] invalid types 'double [100005][double]' for
- 17.[Error] declaration of 'long long int b' shadows a parameter
- 18.[Error] expected unqualified-id before 'case'
- 19.[Error] expected primary-expression before 'case'
- 20.error: expected constructor, destructor, or type conversion before '.' token
- 21.Process exited with return value 3221225477
- 22.[Error] invalid types 'int[int]' for array subscript
- 23.[Error] lvalue required as left operand of assignment
- 24.[Error] base operand of '->' has non-pointer type 'STU {aka student}'
- 25.[Error] request for member 'score' in '\* o', which is of pointer type 'STU\*
- 26.expected '}' at end if input
- 27.提交代码后出现Segmentation Fault
- 28.error C2871: 'std' : a namespace with this name does not exist
- 29.“greater”: 未声明的标识符错误
- 30.[Error] 'unordered_map' was not declared in this scope
- unordered_map头文件报错
- 31.[Error] void value not ignored as it ought to be
- 32.[Error] 'reverse' was not declared in this scope
- 33.[Error] incompatible types in assignment of 'int*' to 'int [100]'
- 34.[Error] expected identifier before '(' token
- 35.VS生成项目时报错:“error LNK 1168:无法打开xxxxxx.exe进行写入
- 36.[Error] request for member 'next' in something not a structure or union
- 37.[Warning] assignment from incompatible pointer type [enabled by default]
- 38.[Error] invalid operands to binary - (have 'int' and 'char *')
- 39.[Error] expected declaration or statement at end of input
- 40.reference to 'next' is ambiguous
- 41.[Error] variably modified 'ma' at file scope
- 42.size of array "f" is too large
- 43.[Error] stray '\241' in program
- 44.[Error] invalid operands of types '__gnu_cxx::__enable_if
1.comparison between pointer and integer :
比较了两种不同类型的变量,指针和整型
2.error: ‘for’ loop initial declarations are only allowed in C99 mode
此部分转载自:https://blog.csdn.net/imyang2007/article/details/8296331
使用gcc编译代码是报出错误:
error: ‘for’ loop initial declarations are only allowed in C99 mode
note: use option -std=c99 or -std=gnu99 to compile your code
这是因为在gcc中直接在for循环中初始化了增量:
//这种语法在gcc中是错误的,必须先定义i变量
for (int i = 0; i < len; i++)
正确写法:
int i;
for (i = 0; i < len; i++)
//这是因为gcc基于c89标准,换成C99标准就可以在for循环内定义i变量了:
//gcc src.c -std=c99 -o src
3.[Error] a function-definition is not allowed here before ‘{’ token
检查函数定义的范围 ,在一个函数内部不允许再定义函数
4.[Error] ‘f’ was not declared in this scope
f 没有进行声明
5.error C2679
此部分转载自:https://blog.csdn.net/a379039233/article/details/83755740
#include <iostream>
//#include <string>int main()
{std::string str = "test";std::cout <<str<< std::endl;return 0;
}
上述代码报错,error: C2679: 二进制“<<”: 没有找到接受“std::string”类。
iostream 里面包含的是老的string代码(Microsoft Visual Studio 14.0\VC\include) xstring,他的代码并没有重载<<操作符,如下图:
而新的C++ 标准string代码(Microsoft Visual Studio 14.0\VC\include\string) 则重载了<<,如下:
所以必须添加头文件,用最新的标准库string。
6.Runtime Error
运行错误,调用了没有分配的内存
- 一般就是数组越界,有可能是数组开小了,数组还是开大点比较好
- 有一次是因为没有在读入变量n时就使用了变量n
- 还有一次是在栈是空的情况下,使用了st.top()
7.[Error] cannot convert ‘int (*)[4]’ to ‘char (*)[4]’ for argument ‘1’ to ‘void row(char (*)[4], int)’
我这一次是因为自定义了一个参数为字符数组的自定义函数,但是输入了一个int类型的数组
8.[Error] ld returned 1 exit status
转载自:https://www.cnblogs.com/kinson/p/7922225.html
1.第一次是因为很粗心地把int main错写成了int msin()
2.第二次是因为写错了自定义函数名
9.[Error] expected constructor, destructor, or type conversion before ‘(’ token
此部分转载自:https://www.cnblogs.com/xiaoZQ/p/5203580.html
10.[Error] ‘pair’ does not name a type
没有写using namespace std;
11.[Error] ‘>>’ should be ‘> >’ within a nested template argument list
需要在两个>之间加一个空格,
把queue<pair<int,int>> q;变成queue<pair<int,int> > q;
12. [Warning] overflow in implicit constant conversion [-Woverflow]
13.[Error] a function-definition is not allowed here before ‘{’ token
在一个函数内部不许再定义函数
14.[Error] reference to ‘map’ is ambiguous
自定义的map变量与库中重名,修改为其他变量名即可
同样,有时候end、left、right作为变量名时也会与库中的发生冲突
15.[Error] declaration of ‘int x [3]’ shadows a parameter
16.[Error] invalid types ‘int[int]’ for array subscript
误把一个int变量当成了数组名使用
[Error] invalid types ‘double [100005][double]’ for
同理,把一个double型变量当成了数组名
17.[Error] declaration of ‘long long int b’ shadows a parameter
原因是定义了相同的变量
18.[Error] expected unqualified-id before ‘case’
19.[Error] expected primary-expression before ‘case’
把代码中的case改成Case就不会出现这样的情况,应该是case与标准库里的名称起了冲突。
20.error: expected constructor, destructor, or type conversion before ‘.’ token
链接:https://blog.csdn.net/glp_hit/article/details/8635049
21.Process exited with return value 3221225477
这表示编译的时候出现了错误,我这次是因为超出了定义的数组的空间。
22.[Error] invalid types ‘int[int]’ for array subscript
我这次是因为定义了一个int n;和一个int n[100];名称冲突了
23.[Error] lvalue required as left operand of assignment
https://blog.csdn.net/kerouacs/article/details/79291762
24.[Error] base operand of ‘->’ has non-pointer type ‘STU {aka student}’
声明变量时,下面这样是定义了一个STU *型的变量p和一个STU型的变量a。
STU *p, a;
如果要定义两个STU *型的变量,需要写成
STU *p, *a;
25.[Error] request for member ‘score’ in ‘* o’, which is of pointer type 'STU*
*p->a这样是不对的,应该写成(*p)->a
26.expected ‘}’ at end if input
一般这种情况就是缺大括号
27.提交代码后出现Segmentation Fault
段错误就是指访问的内存超过了系统所给这个程序的内存空间,需要检查有没有内存溢出
可能是访问了没有规定的内存,比如数组的arr[-1]
https://blog.csdn.net/u010150046/article/details/77775114
28.error C2871: ‘std’ : a namespace with this name does not exist
今天用POJ做题才知道,如果要用using namespace std;的话前面的头文件要有#inlcude<iostream>,否则会出现编译错误
链接:https://blog.csdn.net/zhenshiyiqie/article/details/8445237
29.“greater”: 未声明的标识符错误
头文件加上#include<functional>
30.[Error] ‘unordered_map’ was not declared in this scope
unordered_map头文件报错
由于Devcpp比较老了,会出现这个问题
解决方法:
1)如果不想修改代码,可以直接在OJ上进行编译,OJ的C++版本一般比较新,都会支持unordered_map
如果需要在本地进行编译,有如下的方法:
2)https://blog.csdn.net/fantasy_94/article/details/86425018
3)https://www.cnblogs.com/llllrj/p/9510239.html
31.[Error] void value not ignored as it ought to be
使用的一个函数的返回值类型是void,而有对它进行了赋值处理。
32.[Error] ‘reverse’ was not declared in this scope
我这次是因为没有写algorithm头文件,reverse函数在这个头文件内。
33.[Error] incompatible types in assignment of ‘int*’ to ‘int [100]’
https://zhidao.baidu.com/question/137297696.html
34.[Error] expected identifier before ‘(’ token
https://blog.csdn.net/qq_40732350/article/details/82946117
我这次是因为给一个自定义函数起名为union,改成Union之后就好了
35.VS生成项目时报错:“error LNK 1168:无法打开xxxxxx.exe进行写入
https://blog.csdn.net/qq_27565063/article/details/80658718
36.[Error] request for member ‘next’ in something not a structure or union
没有正确的使用next类型,注意看一下next的类型
37.[Warning] assignment from incompatible pointer type [enabled by default]
不同类型的指针进行了赋值
38.[Error] invalid operands to binary - (have ‘int’ and ‘char *’)
int类型和char*类型的变量在同一行
39.[Error] expected declaration or statement at end of input
我这次是因为某个地方少了一个括号
还有可能是某一个函数或者变量没有在使用之前声明。
40.reference to ‘next’ is ambiguous
next跟库里的属性或方法重名了
上面的next是和iostream里的内容重名了,删除了头文件iostream就好了
41.[Error] variably modified ‘ma’ at file scope
https://blog.csdn.net/zhaohaibo_/article/details/89322902
42.size of array “f” is too large
之前开了一个f[1<<20+5][20]f[1<<20+5][20]f[1<<20+5][20]的数组,报出了上面的错误
改成了f[1<<20][20]f[1<<20][20]f[1<<20][20]就没事了
43.[Error] stray ‘\241’ in program
所在行出现了非法字符
晕死,居然是有一个看不见的非法字符,将报错行周围的空白都删去就好了
https://blog.csdn.net/pijiuxiaolongxia/article/details/90145731
44.[Error] invalid operands of types ‘__gnu_cxx::__enable_if<true, double>::__type {aka double}’ and ‘int’ to binary ‘operator%’
abs函数在C语言中包含在 stdlib.h 头文件中,在C++中包含在 cmath 头文件中
如果用的头文件是 cmath 并且像下面这么写,就会报错
res = abs(a - b) % 2; //报错
解决方法:
方法一:用一个变量来接收 abs(a-b)
d = abs(a - b);
res = d % 2;
方法二:改用 stdlib.h 头文件
#include <stdlib.h>
45、[Error] assignment to expression with array type
感谢疾风大佬的补充
C/C++一些常见的错误相关推荐
- 浅显易懂 Makefile 入门 (12)— Makefile 常见的错误信息
1. 常见的错误信息 make 执行过程中所产生错误并不都是致命的,特别是在命令行之前存在 -.或者 make 使用 -k 选项执行时. make 执行过程的致命错误都带有前缀字符串 ***.错误信息 ...
- PCL安装常见的错误集合解决方案(一)
常见的错误集合解决方案(一) No.1 提示错误 'Microsoft.VC90.CRT,version="9.0.21022.8" 把Microsoft.NET Framewor ...
- 常见 Datagrid 错误
Marcie Robillard DatagridGirl.com Datagrid 控件是 Microsoft® ASP.NET 中功能最强.用途最广的 Web 控件之一,这一点已经得到了 ASP. ...
- 8种常见SQL错误用法
点击上方"方志朋",选择"设为星标" 做积极的人,而不是积极废人 来源:https://dwz.cn/cgAPOWPx 1.LIMIT 语句 分页查询是最常用的 ...
- php中常见的错误类型有,JavaScript中常见的错误类型有哪些?(详细介绍)
在JavaScript中,当发生错误时会生成描述错误类型的错误对象,此错误对象包含错误类型和编号等信息,这些信息可用于后续处理等,在本篇文章中将给大家介绍常见的错误类型以及如何处理这些错误. Java ...
- 你应该避免的8种常见SQL错误用法!
来源:https://dwz.cn/cgAPOWPx 1.LIMIT 语句 分页查询是最常用的场景之一,但也通常也是最容易出问题的地方. 比如对于下面简单的语句,一般 DBA 想到的办法是在 type ...
- Nginx常见的错误及解决方法
1.Nginx 常见启动错误 有的时候初次安装nginx的时候会报这样的错误 sbin/nginx -c conf/nginx.conf 报错内容:sbin/nginx: error while lo ...
- 《C语言程序设计:问题与求解方法》——3.9节常见编程错误
本节书摘来自华章社区<C语言程序设计:问题与求解方法>一书中的第3章,第3.9节常见编程错误,作者:何 勤,更多章节内容可以访问云栖社区"华章社区"公众号查看 3.9 ...
- 初学Python常见异常错误,总有一处你会遇到!
初学Python常见异常错误,总有一处你会遇到! 参考文章: (1)初学Python常见异常错误,总有一处你会遇到! (2)https://www.cnblogs.com/xxpythonxx/p/1 ...
- 使用虚拟机安装Linux系统常见的错误以及解决方案
使用虚拟机安装Linux系统常见的错误以及解决方案 参考文章: (1)使用虚拟机安装Linux系统常见的错误以及解决方案 (2)https://www.cnblogs.com/yanjiexiansh ...
最新文章
- iscsi-server端配置,以及clients连接。
- C++中的覆盖(重写)、重载、隐藏(重定义)、多态!
- html怎么调整成苹方,html苹方字体
- IO流配置文件,键值对Properties 的读取
- springboot 远程调用shell脚本,环境为windows
- SLF4J源码解析-LoggerFactory(二)
- 为什么打印机打印照片模糊_家用喷墨打印机打印照片不清楚怎么办 是什么原因?...
- 制作Lightbox效果
- 【每日一练】64—CSS实现彩虹文字的动画效果
- 计算机13E怎么转换成十进制,十六进制换算(进制转换计算器)
- excel表格,如何按编号换行
- PL SQL中如何去掉字符串中重复的字符
- 遇事不决,量子力学;不懂配色,赛博朋克。推荐一个Python可视化库
- 【OpenPCDet】Kitti数据集下训练PointPillars并评估可视化
- java的前端还是后端_java语言是开发前端还是后端的
- 哪些动物拥有惊人的数学天赋?
- 写一个爱心的R语言代码
- Office选装 + Visio安装
- 手把手教你更改maven镜像源
- cisco+ppoe+nat