当前位置: 移动技术网 > IT编程>开发语言>C/C++ > C语言开发中常见报错的解决方案

C语言开发中常见报错的解决方案

2019年06月17日  | 移动技术网IT编程  | 我要评论

微微一笑很倾城txt下载新浪,娘娘 奴才有了,3d字图迷

c语言开发中常见报错的解决方案

整理来源于网络,侵权请通知删除。*禁止转载
----

fatal error c1003: error count exceeds number; stopping compilation
中文对照:(编译错误)错误太多,停止编译
解决方案:修改之前的错误,再次编译


fatal error c1004: unexpected end of file found
中文对照:(编译错误)文件未结束
解决方案:一个函数或者一个结构定义缺少“}”、或者在一个函数调用或表达式中括号没有配对出现、或者注释符“//”不完整等


fatal error c1083: cannot open include file: 'xxx': no such file or directory
中文对照:(编译错误)无法打开头文件 xxx:没有这个文件或路径
解决方案:头文件不存在、或者头文件拼写错误、或者文件为只读


fatal error c1903: unable to recover from previous error(s); stopping compilation
中文对照:(编译错误)无法从之前的错误中恢复,停止编译
解决方案:引起错误的原因很多,建议先修改之前的错误


error c2001: newline in constant
中文对照:(编译错误)常量中创建新行
解决方案:字符串常量多行书写


error c2006: #include expected a filename, found 'identifier'
中文对照:(编译错误)#include 命令中需要文件名
解决方案:一般是头文件未用一对双引号或尖括号括起来,例如“#include stdio.h”


error c2007: #define syntax
中文对照:(编译错误)#define 语法错误
解决方案:例如“#define”后缺少宏名,例如“#define”


error c2008: 'xxx' : unexpected in macro definition
中文对照:(编译错误)宏定义时出现了意外的 xxx
解决方案:宏定义时宏名与替换串之间应有空格,例如“#define true"1"”


error c2009: reuse of macro formal 'identifier'
中文对照:(编译错误)带参宏的形式参数重复使用
解决方案:宏定义如有参数不能重名,例如“#define s(a,a) (a*a)”中参数 a 重复


error c2010: 'character' : unexpected in macro formal parameter list
中文对照:(编译错误)带参宏的形式参数表中出现未知字符
解决方案:例如“#define s(r|) r*r”中参数多了一个字符‘|’


error c2014: preprocessor command must start as first nonwhite space
中文对照:(编译错误)预处理命令前面只允许空格
解决方案:每一条预处理命令都应独占一行,不应出现其他非空格字符


error c2015: too many characters in constant
中文对照:(编译错误)常量中包含多个字符
解决方案:字符型常量的单引号中只能有一个字符,或是以“”开始的一个转义字符, 例如“char error = 'error';”


error c2017: illegal escape sequence
中文对照:(编译错误)转义字符非法
解决方案:一般是转义字符位于 ' ' 或 " " 之外,例如“char error = ' '\n;”


error c2018: unknown character '0xhh'
中文对照:(编译错误)未知的字符 0xhh
解决方案:一般是输入了中文标点符号,例如“char error = 'e';”中“;”为中文标点符号


error c2019: expected preprocessor directive, found 'character'
中文对照:(编译错误)期待预处理命令,但有无效字符
解决方案:一般是预处理命令的#号后误输入其他无效字符,例如“#!define true 1”


error c2021: expected exponent value, not 'character'
中文对照:(编译错误)期待指数值,不能是字符
解决方案:一般是浮点数的指数表示形式有误,例如 123.456e


error c2039: 'identifier1' : is not a member of 'identifier2'
中文对照:(编译错误)标识符 1 不是标识符 2 的成员
解决方案:程序错误地调用或引用结构体、共用体、类的成员


error c2041: illegal digit 'x' for base 'n'
中文对照:(编译错误)对于 n 进制来说数字 x 非法
解决方案:一般是八进制或十六进制数表示错误,例如“int i = 081;”语句中数字‘8’不是八进制的基数


rror c2048: more than one default
中文对照:(编译错误)default 语句多于一个
解决方案:switch 语句中只能有一个 default,删去多余的 default


error c2050: switch expression not integral
中文对照:(编译错误)switch 表达式不是整型的
解决方案:switch 表达式必须是整型(或字符型),例如“switch ("a")”中表达式为字符串,这是非法的


error c2051: case expression not constant
中文对照:(编译错误)case 表达式不是常量
解决方案:case 表达式应为常量表达式,例如“case"a"”中“"a"”为字符串,这是非法的


error c2052: 'type' : illegal type for case expression
中文对照:(编译错误)case 表达式类型非法
解决方案:case 表达式必须是一个整型常量(包括字符型)


error c2057: expected constant expression
中文对照:(编译错误)期待常量表达式
解决方案:一般是定义数组时数组长度为变量,例如“int n=10; int a[n];”中 n 为变量,这是非法的


error c2058: constant expression is not integral
中文对照:(编译错误)常量表达式不是整数
解决方案:一般是定义数组时数组长度不是整型常量


error c2059: syntax error : 'xxx'
中文对照:(编译错误)‘xxx’语法错误
解决方案:引起错误的原因很多,可能多加或少加了符号 xxx


error c2064: term does not evaluate to a function
中文对照:(编译错误)无法识别函数语言
解决方案:
(1)函数参数有误,表达式可能不正确,例如“sqrt(s(s-a)(s-b)(s-c));”中表达式不正确
(2)变量与函数重名或该标识符不是函数,例如“int i,j; j=i();”中 i 不是函数


error c2065: 'xxx' : undeclared identifier
中文对照:(编译错误)未定义的标识符 xxx
解决方案:

(1) 如果 xxx 为 cout、cin、scanf、printf、sqrt 等,则程序中包含头文件有误

(2) 未定义变量、数组、函数原型等,注意拼写错误或区分大小写。


error c2078: too many initializers
中文对照:(编译错误)初始值过多
解决方案:一般是数组初始化时初始值的个数大于数组长度,例如“int b[2]={1,2,3};”


error c2082: redefinition of formal parameter 'xxx'
中文对照:(编译错误)重复定义形式参数 xxx
解决方案:函数首部中的形式参数不能在函数体中再次被定义


error c2084: function 'xxx' already has a body
中文对照:(编译错误)已定义函数 xxx
解决方案:在 vc++早期版本中函数不能重名,6.0版本中支持函数的重载,函数名可以相同但参数不一样


error c2086: 'xxx' : redefinition
中文对照:(编译错误)标识符 xxx 重定义
解决方案:变量名、数组名重名


error c2087: '' : missing subscript
中文对照:(编译错误)下标未知
解决方案:一般是定义二维数组时未指定第二维的长度,例如“int a[3][];”


error c2100: illegal indirection
中文对照:(编译错误)非法的间接访问运算符“
解决方案:对非指针变量使用“
”运算


error c2105: 'operator' needs l-value
中文对照:(编译错误)操作符需要左值
解决方案:例如“(a+b)++;”语句,“++”运算符无效


error c2106: 'operator': left operand must be l-value
中文对照:(编译错误)操作符的左操作数必须是左值
解决方案:例如“a+b=1;”语句,“=”运算符左值必须为变量,不能是表达式


error c2110: cannot add two pointers
中文对照:(编译错误)两个指针量不能相加
解决方案:例如“intpa,pb,*a;a=pa+pb;”中两个指针变量不能进行“+”运算


error c2117: 'xxx' : array bounds overflow
中文对照:(编译错误)数组 xxx 边界溢出
解决方案:一般是字符数组初始化时字符串长度大于字符数组长度,例如“char str[4] = "abcd";”


error c2118: negative subscript or subscript is too large
中文对照:(编译错误)下标为负或下标太大
解决方案:一般是定义数组或引用数组元素时下标不正确


error c2124: divide or mod by zero
中文对照:(编译错误)被零除或对 0 求余
解决方案:例如“int i = 1 / 0;”除数为 0


error c2133: 'xxx' : unknown size
中文对照:(编译错误)数组 xxx 长度未知
解决方案:一般是定义数组时未初始化也未指定数组长度,例如“int a[];”


error c2137: empty character constant。
中文对照:(编译错误)字符型常量为空
解决方案:一对单引号“''”中不能没有任何字符


error c2143: syntax error : missing 'token1' before 'token2'
error c2146: syntax error : missing 'token1' before identifier 'identifier'
中文对照:(编译错误)在标识符或语言符号 2 前漏写语言符号 1
解决方案:可能缺少“{”、“)”或“;”等语言符号


error c2144: syntax error : missing ')' before type 'xxx'
中文对照:(编译错误)在 xxx 类型前缺少‘)’
解决方案:一般是函数调用时定义了实参的类型


error c2181: illegal else without matching if
中文对照:(编译错误)非法的没有与 if 相匹配的 else
解决方案:可能多加了“;”或复合语句没有使用“{}”


error c2196: case value '0' already used
中文对照:(编译错误)case 值 0 已使用
解决方案:case 后常量表达式的值不能重复出现


error c2296: '%' : illegal, left operand has type 'float'
error c2297: '%' : illegal, right operand has type 'float'
中文对照:(编译错误)%运算的左(右)操作数类型float,这是非法的
解决方案:求余运算的对象必须均为int类型,应正确定义变量类型或使用强制类型转换


error c2371: 'xxx' : redefinition; different basic types
中文对照:(编译错误)标识符 xxx 重定义;基类型不同
解决方案:定义变量、数组等时重名


error c2440: '=' : cannot convert from 'char [2]' to 'char'
中文对照:(编译错误)赋值运算,无法从字符数组转换为字符
解决方案:不能用字符串或字符数组对字符型数据赋值,更一般的情况,类型无法转换


error c2448: '' : function-style initializer appears to be a function definition
中文对照:(编译错误)缺少函数标题(是否是老式的形式表?)
解决方案:函数定义不正确,函数首部的“()”后多了分号或者采用了老式的 c 语言的形参表


error c2450: switch expression of type 'xxx' is illegal
中文对照:(编译错误)switch 表达式为非法的 xxx 类型
解决方案:switch 表达式类型应为 int 或 char


error c2466: cannot allocate an array of constant size 0
中文对照:(编译错误)不能分配长度为 0 的数组
解决方案:一般是定义数组时数组长度为 0


error c2601: 'xxx' : local function definitions are illegal
中文对照:(编译错误)函数 xxx 定义非法
解决方案:一般是在一个函数的函数体中定义另一个函数


error c2632: 'type1' followed by 'type2' is illegal
中文对照:(编译错误)类型 1 后紧接着类型 2,这是非法的
解决方案:例如“int float i;”语句


error c2660: 'xxx' : function does not take n parameters
中文对照:(编译错误)函数 xxx 不能带 n 个参数
解决方案:调用函数时实参个数不对,例如“sin(x,y);”


error c2664: 'xxx' : cannot convert parameter n from 'type1' to 'type2'
中文对照:(编译错误)函数 xxx 不能将第 n 个参数从类型 1 转换为类型 2
解决方案:一般是函数调用时实参与形参类型不一致


error c2676: binary '<<' : 'class istream_withassign' does not define this operator or a conversion to a type acceptable to the predefined operator
error c2676: binary '>>' : 'class ostream_withassign' does not define this operator or a conversion to a type acceptable to the predefined operator
解决方案:“>>”、“<<”运算符使用错误,例如“cin<<x; cout>>y;”


error c4716: 'xxx' : must return a value
中文对照:(编译错误)函数 xxx 必须返回一个值
解决方案:仅当函数类型为 void时,才能使用没有返回值的返回命令。


fatal error lnk1104: cannot open file "debug/cpp1.exe"
中文对照:(链接错误)无法打开文件 debug/cpp1.exe
解决方案:重新编译链接


fatal error lnk1168: cannot open debug/cpp1.exe for writing
中文对照:(链接错误)不能打开 debug/cpp1.exe文件,以改写内容。
解决方案:一般是 cpp1.exe 还在运行,未关闭


fatal error lnk1169: one or more multiply defined symbols found
中文对照:(链接错误)出现一个或更多的多重定义符号。
解决方案:一般与 error lnk2005 一同出现


error lnk2001: unresolved external symbol _main
中文对照:(链接错误)未处理的外部标识 main
解决方案:一般是 main 拼写错误,例如“void mian()”


error lnk2005: _main already defined in cpp1.obj
中文对照:(链接错误)main 函数已经在 cpp1.obj 文件中定义
解决方案:未关闭上一程序的工作空间,导致出现多个 main 函数


warning c4003: not enough actual parameters for macro 'xxx'
中文对照:(编译警告)宏 xxx 没有足够的实参
解决方案:一般是带参宏展开时未传入参数


warning c4067: unexpected tokens following preprocessor directive -expected a newline
中文对照:(编译警告)预处理命令后出现意外的符号-期待新行
解决方案:“#include<iostream.h>;”命令后的“;”为多余的字符


warning c4091: '' : ignored on left of 'type' when no variable is declared
中文对照:(编译警告)当没有声明变量时忽略类型说明
解决方案:语句“int ;”未定义任何变量,不影响程序执行


warning c4101: 'xxx' : unreferenced local variable
中文对照:(编译警告)变量xxx定义了但未使用
解决方案:可去掉该变量的定义,不影响程序执行


warning c4244: '=' : conversion from 'type1' to 'type2', possible lossof data
中文对照:(编译警告)赋值运算,从数据类型 1 转换为数据类型 2,可能丢失数据
解决方案:需正确定义变量类型,数据类型1为float或double、数据类型 2 为 int时,结果有可能不正确,数据类型 1 为 double、数据类型 2 为 float 时,不影响程序结果,可忽略该警告


warning c4305: 'initializing' : truncation from 'const double' to 'float'
中文对照:(编译警告)初始化,截取双精度常量为 float 类型
解决方案:出现在对 float 类型变量赋值时,一般不影响最终结果


warning c4390: ';' : empty controlled statement found; is this the intent?
中文对照:(编译警告)‘;’控制语句为空语句,是程序的意图吗?
解决方案:if 语句的分支或循环控制语句的循环体为空语句,一般是多加了“;”


warning c4508: 'xxx' : function should return a value; 'void' return type assumed
中文对照:(编译警告)函数 xxx 应有返回值,假定返回类型为 void
解决方案:一般是未定义 main 函数的类型为 void,不影响程序执行


warning c4552: 'operator' : operator has no effect; expected operator with side-effect
中文对照:(编译警告)运算符无效果;期待副作用的操作符
解决方案:例如“i+j;”语句,“+”运算无意义


warning c4553: '==' : operator has no effect; did you intend '='?
中文对照:(编译警告)“==”运算符无效;是否为“=”?
解决方案:例如 “i==j;” 语句,“==”运算无意义

warning c4700: local variable 'xxx' used without having been initialized
中文对照:(编译警告)变量 xxx 在使用前未初始化
解决方案:变量未赋值,结果有可能不正确,如果变量通过 scanf 函数赋值,则有可能漏写“&”运算符,或变量通过 cin 赋值,语句有误


warning c4715: 'xxx' : not all control paths return a value
中文对照:(编译警告)函数 xxx 不是所有的控制路径都有返回值
解决方案:一般是在函数的 if 语句中包含 return 语句,当 if 语句的条件不成立时没有返回值


warning c4723: potential divide by 0
中文对照:(编译警告)有可能被 0 除
解决方案:表达式值为 0 时不能作为除数


warning c4804: '<' : unsafe use of type 'bool' in operation
中文对照:(编译警告)‘<’:不安全的布尔类型的使用
解决方案:例如关系表达式“0<=x<10”有可能引起逻辑错误

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网