| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
共有 2413 人关注过本帖
标题:为什么我的VC不能通过?
取消只看楼主 加入收藏
隐藏着的某人
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2006-10-8
收藏
 问题点数:0 回复次数:1 
为什么我的VC不能通过?
这段代码是我从书上抄下来的!但是不能编译通过! 我想了很久! 我用的是vc 6.0 别人用其他编译器就能通过!谁帮我改改让在VC 上也能通过!
#include <iostream>
#include <iomanip>
using namespace std;
class Time{
int hour,minute,second;
public:
void set(int h,int m,int s){hour=h,minute=m,second=s;}
friend Time& operator++(Time& a);
friend Time operator++(Time& a,int);
friend ostream& operator<<(ostream& out,const Time& t);
};
Time& operator++(Time& a){
if(!(a.second=(a.second+1)%60)&&!(a.minute=(a.minute)%60))
a.hour=(a.hour+1)%24;
return a;
}
Time operator++(Time& a,int){
Time t(a);
if(!(a.second=(a.second+1)%60)&&!(a.minute=(a.minute)%60))
a.hour=(a.hour+1)%24;
return t;
}
ostream& operator<<(ostream& out,const Time& t){
out<<setfill('0')<<setw(2)<<t.hour<<":"<<setfill('0')<<setw(2)<<t.minute<<":";
return out<<setw(2)<<t.second<<"\n"<<setfill(' ');
}
int main(){
Time t;
t.set(11,59,58);
cout<<t++;
cout<<++t;
}

为了我的游戏事业而奋斗
2006-10-30 12:51
隐藏着的某人
Rank: 1
等 级:新手上路
帖 子:29
专家分:0
注 册:2006-10-8
收藏
得分:0 
我终于找到错误了!是名空间的问题! 改成这样就好了
#include <iostream>
#include <iomanip>
using namespace std;
class Time{
int hour,minute,second;
public:
void set(int h,int m,int s){hour=h,minute=m,second=s;}
friend Time& operator++(Time& a);
friend Time operator++(Time& a,int);
friend ostream& operator<<(ostream& out,const Time& t);
};
Time& operator++(Time& a){
if(!(a.second=(a.second+1)%60)&&!(a.minute=(a.minute+1)%60))
a.hour=(a.hour+1)%24;
return a;
}
Time operator++(Time& a,int){
Time t(a);
if(!(a.second=(a.second+1)%60)&&!(a.minute=(a.minute+1)%60))
a.hour=(a.hour+1)%24;
return t;
}
ostream& std::operator<<(ostream& out,const Time& t){
out<<setfill('0')<<setw(2)<<t.hour<<":"<<setfill('0')<<setw(2)<<t.minute<<":";
return out<<setw(2)<<t.second<<"\n"<<setfill(' ');
}
int main(){
Time t;
t.set(11,59,58);
cout<<t++;
cout<<++t;
}
二楼的也是正解哈! 直接载入
#include <iostream.h>
#include <iomanip.h> 不使用名空间std, 也能成功!谢谢大家的帮助哈! 我没用其他的编译器,VC6还是很不错的哈!

为了我的游戏事业而奋斗
2006-10-30 18:25
快速回复:为什么我的VC不能通过?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013924 second(s), 8 queries.
Copyright©2004-2025, BC-CN.NET, All Rights Reserved