编译时出现的(error C2632: 'long' followed by 'long' is illegal )非法定义的问题
来源:互联网 发布:东北证券软件 编辑:程序博客网 时间:2024/05/16 08:14
编译环境为:Visual C++ 6.0
题目:
求1+2+3+...+n的值。
修改前代码:#include<stdio.h>int main(){int i,n;printf("n=");scanf("%d",&n);while(n){long long sum=0;for(i=1;i<=n;i++){sum+=i;}printf("sum=%I64d\n",sum);printf("n=");scanf("%d",&n);}return 0;}(在对代码段进行编译时,出现error C2632: 'long' followed by 'long' is illegal 报错。)
报错图:
原因:
因为 VC6中所使用的编译器是C90标准的,而 long long型是在C99中新加入的
(longlong int双长整型是C 99扩充的数据类型,同时扩充的还有float_complex,double_complex,long
long_complex,bool等),故无法实现编译。(——此答案搜索于百度)
解决办法:
将long long 用 _int64 进行替换。
修改后代码如下:
#include<stdio.h>int main(){int i,n;printf("n=");scanf("%d",&n);while(n){_int64 sum=0;for(i=1;i<=n;i++){sum+=i;}printf("sum=%I64d\n",sum);printf("n=");scanf("%d",&n);}return 0;}
总结:
①本题代码简单,但请注意本题的数据规模。本题直接的想法是直接使用一个循环进行累加,然而,当数据规模很大时,暴力”的方法会导致超时。
②本题如果使用整型int来保存结果,会导致结果错误。用使用printf输出结果时,则你的格式字符串应该写成%I64d以输出long long类型的整数。
③VisualC++6.0 环境运行下,将long long 用 _int64 进行替换。
阅读全文
0 0
- 编译时出现的(error C2632: 'long' followed by 'long' is illegal )非法定义的问题
- error C2632: 'long' followed by 'long' is illegal
- 'long' followed by 'long' is illegal
- VC下'long' followed by 'long' is illegal
- “BOOLEAN”: 重定义;不同的基类型 ”问题 rpcndr.h(147) : error C2632: “char”后面的“int”非法
- error C2628: 'MySA' followed by 'float' is illegal (did you forget a ';'?) //class定义}后没有;
- 编译内核出现fatal error:XX File name too long的问题
- Long和long的问题
- unsigned long long的问题
- error C2628: followed by 'char' is illegal (did you forget a ';'?)
- error C2628: followed by 'char' is illegal (did you forget a ';'?)
- error C2628: 'TestClass' followed by 'int' is illegal (did you forget a ';'?)
- 备忘:编译Apache的configure: error: Size of "void *" is less than size of "long"错误
- 编译httpd的configure: error: Size of "void *" is less than size of "long"
- ubuntu64位下交叉编译opencv3.3遇到的make[error]error: call of overloaded 'abs(long long int&)' is ambiguous
- unsigned long的问题
- 编译出现File name too long问题
- Long Long 的使用
- 用一段简单代码看JVM的执行过程
- 如何更新R以及RStudio
- java 异常java.lang.UnsupportedOperationException ---EmptyList此集合竟然没有相应的add,remove等方法
- 为你的Android Studio更换好看的主题风格
- 最长的有效括号序列长度
- 编译时出现的(error C2632: 'long' followed by 'long' is illegal )非法定义的问题
- Apache默认端口80被占用无法启动服务问题
- DCT变换的基函数与基图像
- Android:解决style文件不能使用自定义属性
- 前端提升方法
- 插值器InterPolator & Evaluator
- Java的语言特点
- 如何成为一名高薪构架师?
- 打印当前时间,学习使用Date类和Calendar类