一个小错误!

wendream 2007-06-22 09:22:41
编程环境为: vs2003

当源代码为:

#include "iostream"

int sum(int a[],int n);

using namespace std;
int main()
{
int a[10]={0,1,2,3,4,5,6,7,8,9};
int result=0;
cout<<result;
cin.get();
return 0;
}

int sum(int a[],int n )
{
if (n>0) return a[n]+sum(&a[0],n-1);
else return 0;
}

编译不成功, 出现的提示为: fatal error C1001: c:\program files\microsoft visual studio .net 2003\vc7\include\xlocale(116): fatal error C1001: 内部编译器错误 (编译器文件“f:\vs70builds\3077\vc\Compiler\Utc\src\P2\main.c”,第 148 行)

当把源代码修改为:

//#include "iostream"



//int sum(int a[],int n);

//using namespace std;
int main()
{
int a[10]={0,1,2,3,4,5,6,7,8,9};
int result=0;
//cout<<result;
//cin.get();
return 0;
}

//int sum(int a[],int n )
//{
// if (n>0) return a[n]+sum(&a[0],n-1);
// else return 0;
//}

就能够通过编译,是否是我的代码有问题呢?


...全文
252 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
guxingfeiyu 2007-06-25
  • 打赏
  • 举报
回复
Chiyer(星羽) ( ) 信誉:100 Blog 加为好友 2007-6-22 9:33:40 得分: 0



把 main.c 改成 main.cpp 看看

是不是用c编了?



支持。
wendream 2007-06-25
  • 打赏
  • 举报
回复
多谢各位的关注,这个应该是编译环境的问题。

我在家中电脑上试过,没有问题。
在单位电脑上用就有上面提到的问题。

我很久没来这里讨论问题了,谢谢你们!
czlyc006 2007-06-23
  • 打赏
  • 举报
回复
发现sum函数好像没用上
coldplay968 2007-06-23
  • 打赏
  • 举报
回复
没问题
tigerweichao 2007-06-22
  • 打赏
  • 举报
回复
确实没问题
SoftBomb 2007-06-22
  • 打赏
  • 举报
回复
重装一次vc就行了
fengdream 2007-06-22
  • 打赏
  • 举报
回复
重新建立一个工程试试看
lightnut 2007-06-22
  • 打赏
  • 举报
回复
改为.cpp文件, 不是.c文件
星羽 2007-06-22
  • 打赏
  • 举报
回复
把 main.c 改成 main.cpp 看看

是不是用c编了?
jixingzhong 2007-06-22
  • 打赏
  • 举报
回复
没啥问题 ...
jixingzhong 2007-06-22
  • 打赏
  • 举报
回复
#include <iostream>
#include <cstdlib>

int sum(int a[],int n);

using namespace std;
int main()
{
int a[10]={0,1,2,3,4,5,6,7,8,9};
int result=sum(a, 9);
cout<<result;
system("PAUSE");
return 0;
}

int sum(int a[],int n )
{
if (n>0) return a[n]+sum(&a[0],n-1);
else return a[0];
}

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧