IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> C++知识库 -> c语言常见错误合集 -> 正文阅读

[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++)
1
2
正确写法:

int i;
for (i = 0; i < len; i++)
//这是因为gcc基于c89标准,换成C99标准就可以在for循环内定义i变量了:
//gcc src.c -std=c99 -o src
1
2
3
4
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;
}

1
2
3
4
5
6
7
8
9
10
上述代码报错,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;
1
如果要定义两个STU *型的变量,需要写成

STU *p, *a;
1
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; //报错
1
解决方法:

方法一:用一个变量来接收 abs(a-b)

d = abs(a - b);
res = d % 2;
1
2
方法二:改用 stdlib.h 头文件

#include <stdlib.h>
1
45、[Error] assignment to expression with array type
感谢疾风大佬的补充😂

(1)数组不能直接给数组赋值

(2)指针不能直接给数组赋值

解决方法:strcpy函数


默_silence
关注

31

6

143


本文有帮助的话,就点个赞吧T^T1 年前回复

1

_久夏青:补充:[Error] assignment to expression with array type (1)数组不能直接给数组赋值 (2)指针不能直接给数组赋值 解决方法:strcpy函数7 月前回复


_久夏青回复默_silence:嘿嘿嘿😁7 月前回复


默_silence回复:感谢您的补充7 月前回复


考过教资:博主你的学习方法教导我让我懂了必须要时刻记得自己犯得错误防止第二次摔倒在一个地方1 年前回复

c/c++中常见的错误_Frank.Ginger的博客_c++常见错误
10-22
软件编程的过程中,常见的错误有: 1、内存泄露 在c/c++中,内存管理器不会帮助你自动回收不再使用的内存,不管在什么情况下,采取谨慎的态度,杜绝内存泄露的出现,都是上策。尽管一些工具可以帮助我们检查内存泄露问题,但是编程时还是应该仔细...
C/C++常见错误集锦_青萍之末的博客_c++常见错误
9-24
C/C++常见错误集锦 1、error LNK2005:“已经在*.obj中定义” (1) ??变量或者函数的定义放到cpp文件中,不要放到.h中。 (2) #ifndef MY_H_FILE //如果没有定义这个宏#defineMY_H_FILE //定义这个宏…….//头文件主体...
C语言常见错误归纳
weixin_43593986的博客
?1257
#C语言常见错误 一、编译错误 1、缺少分号 2、If else if else switch 未配对,缺少{} 3、参数不匹配 比如 (1) %d------int (2)%ld-----long int (3)%u------unsigned int (4)%f------float (5)%lf-----double (6)%c-----char (7)%s-----char * 4、在非” ”中使用了中文符号 二、运行时错误 1、变量未初始化{be used without…) 在+
C/C++语言常见错误一览表
edg_edu的专栏
?2720
C语言常见错误分析汇总 ? ?C语言的最大特点是:功能强、使用方便灵活。C编译的程序对语法检查并不象其它高级语言那么严格,这就给编程人员留下“灵活的余地”,但还是由于这个灵活给程序的调试带来了许多不便,尤其对初学C语言的人来说,经常会出一些连自己都不知道错在哪里的错误。看着有错的程序,不知该如何改起,本人通过对C的学习,积累了一些C编程时常犯的错误,写给各位学员以供参考。
C/C++常见编译错误整理_TS1130的专栏
9-15
[集合]c/c++常见编译错误 tpriwwq的专栏 4150 C++编译错误 janifer_he的专栏 569 gcc编译c++常见错误汇总 xuwenwu1985的博客 515 C++中一些常见编译错误 Pacer95的博客 1331 1. stray '\343’ in program 源程序中有非法字符,需要将...
C/C++常见报错问题描述及解决方案_时间之里的博客
8-19
C/C++常见报错问题描述及解决方案 C类: 1.窗口运行秒关: 解决方法如下: 若此时进行的操作是编译(F5),可先运行程序(Ctrl+F5),若仍然一闪而过,用下面方法解决。 方法一: 1.若是C++文件,在程序最后写一句(return之前)添加:system...
c/c++软件开发的注意事项
PerfectToday的专栏
?654
<br />c/c++软件开发的注意事项<br />第一部分软件编程的时间分配概况<br /> ? 高效率的程序员并不是敲键盘的速度比别人快,而是他有着良好的编程习惯,节省了别人浪费的时间。因此,要想提高自己的编程效率,根本在于怎么少浪费时间。只要能把别人浪费的时间节省下来,你的效率就可以快过别人,甚至数倍于别人。要想节省时间,当然首先需要明白编程中耗费时间的分配情况。<br />程序员软件开发的几个阶段:<br /> ? 1、分析设计,<br /> ? 分析设计的前提是充分理解需求说明文档,然后分析如何实
delphi中常见错误提示说明
kevinzhaoyp
?5313
?Delphi的中文错误提示; not allowed before ELSE ? ?ElSE前不允许有“;” clause not allowed in OLE automation section 在OLE自动区段不允许“”子句 is not a type identifier 不是类型标识符 not previously declared as a PROPERTY
C、C++各种错误,以及解决办法_舒默哦.的博客
10-14
错误代码: 严重性 代码 说明 项目 文件 行 禁止显示状态 错误C1189 #error: Building MFC application with /MD[d] (CRT dll version) requires MFC shared dll version. Please #define _AFXDLL or do not use /MD[d] Tumbler...
c语言中常见的错误
11-08
c语言中常见的错误分析及代码,以及解决的方法,以后遇到错误就可再次寻找原因。
c语言一些常见错误
最新发布
Shy哥
?40
#define _CRT_SECURE_NO_WARNINGS放在c文件的最开头
C/C++ 常见错误
dongqihaia的专栏
?74
1、下面是一段c程序: void foo(int b[][3]) { ++b; b[1][1]=9; } void main() { int a[3][3]={{1,2,3},{4,5,6},{7,8,9}}; foo(a); printf(“%d”,a[2][1]); } 这段程序的输出是() 1、C/C++传递的数组会退化成指针 2、对于数组指...
【C】报错[Error] lvalue required as left operand of assignment
热门推荐
kerouacs的博客
?12万+
[Error] lvalue required as left operand of assignment原因:计算值为== !=变量为= 赋值语句的左边应该是变量,不能是表达式。而实际上,这里是一个比较表达式,所以要把赋值号(=)改用关系运算符(==)...
c/c++常见编程错误
lcj200813138020的专栏
?290
每次编程出现各种各样的错误,希望以后都总结出来,以备以后好查阅,顺便与同行分享,此篇日志会一直更新,刚开始比较少,以后会越来越多,希望大家多多支持与共同讨论: 1.#define之类的宏后面不要加分号“;”,否则报错。 2linux g++ 报segment fault错误,可能原因: ? a.内存访问越界,常见数组下标越界错误; ? b.非法指针,一类使用空指针,二类随意指针转换,导致访问内存数
c++编程提示function definition is not allowed here
woainilixuhao的博客
?7096
function definition is not allowed here 这是因为函数内部不能再定义函数,
operator does not exist: integer = character varying
夏目_muzi_920316的博客
?1万+
这是postgresql条件查询的时候报的错,前台传来的参数是String 类型,然而数据库中是integer类型,数据库中表:表对应的实体: ? ? ? ? ? ?sql: ? ? ? ? ? ? ? ? ? ?解决办法: ? ? ? ? ? ? ? ?对前台传过来的参数做类型转换,即可!...
解决C/C++:[Error] 'getch' was not declared in this scope
昆石
?7767
编译器编译时出现报错[Error] ‘getch’ was not declared in this scope解决方法 报错的编译器有:VC++6.0/DevC++/IntelliJ IDEA 等 出现[Error] ‘getch’ was not declared in this scope的报错是因为缺少头文件 在你的头文件中加入以下代码即可 #include<conio.h&gt...
GCC-3.4.6源代码学习笔记(129)
wuhui_gdnt的专栏
?1888
<br />5.12.5.2.2. ? ? ? ?函数定义–函数体部分5.12.5.2.2.1. ?准备函数体解析<br />现在我们在decl_specifiers中得到了return-type-specifier,declarator指向CALL_EXPR,而declares_class_or_enum为0。记得如果我们正在定义新类型,declares_class_or_enum是2,这在function-definition中不被允许。<br /> <br />cp_parser_init_dec
python unsupported operand type(s) for /: 'str' and 'str' can only concatenate str (not "int") to s
HWP
?6194
报错: TypeError: can only concatenate str (not “int”) to str TypeError: unsupported operand type(s) for /: ‘str’ and 'str’ python代码部分~ 正确代码: a = int(i

?

  C++知识库 最新文章
【C++】友元、嵌套类、异常、RTTI、类型转换
通讯录的思路与实现(C语言)
C++PrimerPlus 第七章 函数-C++的编程模块(
Problem C: 算法9-9~9-12:平衡二叉树的基本
MSVC C++ UTF-8编程
C++进阶 多态原理
简单string类c++实现
我的年度总结
【C语言】以深厚地基筑伟岸高楼-基础篇(六
c语言常见错误合集
上一篇文章      下一篇文章      查看所有文章
加:2021-10-25 12:21:44  更:2021-10-25 12:23:17 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年4日历 -2024/4/24 14:17:12-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码