Dev C++与VC++的比较?????

cangsangyixiao 2009-01-26 03:14:15
有两个程序:

//Time.cpp
#include <iostream>
#include <stdio.h>
using namespace std;
class Time
{
private:
int hour;
int minute;
int second;
public:
Time(int h,int m,int s);
friend void display(Time&t);
friend Time operator+(const Time&t1,const Time& t2);
friend ostream& operator<<(ostream& output,Time t);
};
Time::Time(int h,int m,int s)
{
hour=h;
minute=m;
second=s;
}
Time operator+(const Time&t1,const Time&t2)
{
return Time(t1.hour+t2.hour,t1.minute+t2.minute,t1.second+t2.second);
}
ostream& operator<<(ostream&output,Time t)
{
output<<t.hour<<':'<<t.minute<<':'<<t.second<<endl;
return output;
}
void display(Time&t)
{
cout<<t.hour<<':'<<t.minute<<':'<<t.second<<endl;
}
int main(void)
{
Time t1(10,30,20);
Time t2(10,10,20);
display(t1);
display(t2);
cout<<(t1+t2);
getchar();
return 0;
}


Time.cpp在Dev C++中正常运行,但在VC++中却不能运行显示如下错误
Time.cpp
d:\test c++\time.cpp(13) : fatal error C1001: INTERNAL COMPILER ERROR
(compiler file 'msc1.cpp', line 1786)
Please choose the Technical Support command on the Visual C++
Help menu, or open the Technical Support help file for more information
执行 cl.exe 时出错.

还有一个程序:

//八皇后问题.cpp(回朔算法)
#include<iostream>
#include <stdlib.h>
#include<stdio.h>
using namespace std;
void Trial(int,int);
int Isleggal(int,int);
int count=0;
const int n=8;
int Queen[n];
int main(void)
{
Trial(0,n);
//cout<<"总共放法有"<<count<<"种"<<endl;
printf("总共方法有%d种",count);
system("pause");
return 0;
}
void Trial(int i,int n)
{
if(i>n-1)
{
count++;
//cout<<"这是第"<<count<<"种放置方法:"<<endl;
printf("这是第%d中放法",count);
for(int k=0;k<n;++k)
{
cout<<"在第"<<k+1<<"列第"<<Queen[k]+1<<"行放一个棋子;";
cout<<endl;
}
}
else
for(int j=0;j<n;++j)
{
Queen[i]=j;
if(Isleggal(i,j))//划分函数模块
Trial(i+1,n);
else
continue;//不满足条件就尝试在下一行放一个棋子
}
}

int Isleggal(int i,int j)
{
int k=0;
while(Queen[k]!=j&&abs(Queen[i]-Queen[k])!=abs(i-k)&&k<i)
++k;
if(k==i) return 1;
else return 0;
}



八皇后问题.cpp在VC++中能正常运行,但在Dev C++却不能通过编译
显示如下错误:
15 F:\Computer Science\我的程序\经典的C程序\八皇后递归.cpp `count' undeclared (first use this function)
23 F:\Computer Science\我的程序\经典的C程序\八皇后递归.cpp `count' undeclared (first use this function)
总结:上述两个程序按照C++的语法都应该是对的,为什么运行会依赖于编译器呢?
...全文
1560 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
SeanHwang 2009-01-27
  • 打赏
  • 举报
回复
只能用标准支持的理由解释~
WillyWonka 2009-01-27
  • 打赏
  • 举报
回复
这个问题很简单,去看看标准的一些CODE就明白了,编译器最好用一些新的,建议VS2008
xuruichen 2009-01-27
  • 打赏
  • 举报
回复
学习ing
Athos_K 2009-01-26
  • 打赏
  • 举报
回复
回楼上,那是为了避免在DEV C++里输出结果的DOS窗口一闪而过。也就是说system("pause");让命令提示符窗口在消失前暂留。
sese53 2009-01-26
  • 打赏
  • 举报
回复
友情UP。随便问问这个是什么意思?
system("pause");
hangyu628 2009-01-26
  • 打赏
  • 举报
回复
微软的编译器是从2003开始支持,标准c++的...
VC++编译器对C++标准支持不好...
qingkongyihe2008 2009-01-26
  • 打赏
  • 举报
回复
多用几个编译器,不同的编译器侧重点不同
sagegz 2009-01-26
  • 打赏
  • 举报
回复
只有一个编译器
waizqfor 2009-01-26
  • 打赏
  • 举报
回复
呵呵 刚才用VC6也试了一下 跟你提示的问题一样 用VS2008就没事 还是支持标准的问题 感觉VC6对友元和摸板的支持都挺差的 经常编译不通过
其实编译器的作用还是为了让你的程序能更加的标准化 认为自己写的程序轻松通过编译阶段 其实不是什么好事 VC6的补丁早就不打了 所以有点东西不支持肯定挺正常 手头里多有几个编译器比较一下
xiaoyisnail 2009-01-26
  • 打赏
  • 举报
回复
对于标准的支持两个编译器差很多
vc6对标准支持比较差,特别是涉及到模板、重载的代码,经常编译不多
另外,有的方面dev-cpp比vc6检查的更严格,所以不能通过编译
dxk01 2009-01-26
  • 打赏
  • 举报
回复
vc6对标准C++的支持不是很好,上面的例子用INTEL编译器或VC2008都没问题。

65,210

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

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