| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 755 人关注过本帖
标题:此程序在错在哪里
取消只看楼主 加入收藏
zjl138
Rank: 1
等 级:新手上路
威 望:1
帖 子:788
专家分:0
注 册:2007-11-12
收藏
 问题点数:0 回复次数:4 
此程序在错在哪里
//f0806.cpp
//Time类的operator++应用
#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& o,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& operator<<(ostream& o,const Time& t)
{o<<setfill('0')<<setw(2)<<t.hour<<":"<<setw(2)<<t.minute<<":"
return o<<setw(2)<<t.second<<"\n"<<setfill(' ');
}
int main()
{Time t;
t.set(11,59,58);
cout<<t++;
cout<<++t;
}
搜索更多相关主题的帖子: void include public friend 
2007-11-14 12:49
zjl138
Rank: 1
等 级:新手上路
威 望:1
帖 子:788
专家分:0
注 册:2007-11-12
收藏
得分:0 

太谢谢一楼了.麻烦你了.
不过我还是有点不明白使用友元时用#include<iostream>与#include<iostream.h>有什么不同.
是不是编译器问题.


i like linux...
2007-11-15 11:52
zjl138
Rank: 1
等 级:新手上路
威 望:1
帖 子:788
专家分:0
注 册:2007-11-12
收藏
得分:0 
那是不是用友元时就要用#include<iostream.h>头文件.
至少在VC++6.0的环境中是不是要这样.

i like linux...
2007-11-15 12:05
zjl138
Rank: 1
等 级:新手上路
威 望:1
帖 子:788
专家分:0
注 册:2007-11-12
收藏
得分:0 
谢谢了

i like linux...
2007-11-15 13:11
zjl138
Rank: 1
等 级:新手上路
威 望:1
帖 子:788
专家分:0
注 册:2007-11-12
收藏
得分:0 

要不麻烦七楼"yuyunliuhen"用#include<iostream>此头文件将上面程序调试出来发给我.不胜感激!!!


i like linux...
2007-11-15 14:54
快速回复:此程序在错在哪里
数据加载中...
 
   



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

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