| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 593 人关注过本帖
标题:求教:程序怎么编译不了,谢谢
只看楼主 加入收藏
linzhaoyang
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2006-4-21
收藏
 问题点数:0 回复次数:9 
求教:程序怎么编译不了,谢谢

我下面的这个程序怎么编译时老提示:D:\Cpp1.cpp(23) : fatal error C1083: Cannot open include file: 'mytime0.h': No such file or directory

//mytime0.h
#ifndef mytime_h
#define mytime_h
class Time
{
private:
int hours;
int minutes;
public:
Time();
Time(int h,int m=0);
void addmin(int m);
void addhr(int h);
void reset(int h=0,int m=0);
Time operator+(const Time & t)const;
void show()const;
};
#endif


//mytime0.cpp
#include <iostream>
#include "mytime0.h"

Time::Time()
{
hours=minutes=0;
}
Time::Time(int h,int m)
{
hours=h;
minutes=m;
}
void Time::addmin(int m)
{
minutes+=m;
hours+=minutes/60;
minutes%=60;
}
void Time::addhr(int h)
{
hours+=h;
}
void Time::reset(int h,int m)
{
hours=h;
minutes=m;
}
Time Time::operator(const Time & t)const
{
Time sum;
sum.minutes=minutes+t.minutes;
sum.hours=hours+t.hours+sum.minutes/60;
sum.minutes%=60;
return sum;
}
void Time::show()const
{
std::cout<< hours<<"hours,"<<minutes<<"minutes";
}
//usetime0.cpp
#include<iostream>
#include"mytime.h"
using namespace std;
int mian()
{
Time play;
Time coding(2,40);
Time fixing(5,55);
Time total;

cout << "play time is ";
play.show();
cout << endl;

cout << "coding time is ";
coding.show();
cout << endl;

cout << "fixing time is ";
fixing.show();
cout << endl;

total=coding+fixing;
cout << "coding+fixing is ";
total.show();
cout << endl;

return 0;

}

搜索更多相关主题的帖子: int void 编译 Time 
2006-04-21 10:37
踏魔狼
Rank: 6Rank: 6
等 级:贵宾
威 望:24
帖 子:1322
专家分:33
注 册:2005-9-22
收藏
得分:0 
你的第一个文件是mytime0.h还是mytime.h。
为什么你的主文件包含的是mytime.h。

=×&D o I p R e E n C g T l X&×=
2006-04-21 11:14
柳儿
Rank: 6Rank: 6
等 级:贵宾
威 望:25
帖 子:1830
专家分:30
注 册:2004-9-23
收藏
得分:0 
而且错误提示的Cpp1.cpp是哪个啊?
main函数还写错

成功会使人骄傲。如果你骄傲自大,你就会停止学习。不学习,人就停止了进步
2006-04-21 11:23
linzhaoyang
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2006-4-21
收藏
得分:0 
请问改过了怎么还不行的?
麻烦楼上能不能调试一下,是不是我没装什么补丁之类的,我的所有的包含类定义的程序都这样的,谢谢
2006-04-21 11:49
linzhaoyang
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2006-4-21
收藏
得分:0 
楼上:
我现在主要想知道的是为什么有那样的提示?为什么会打不开mytime0.h文件?
呢?
谢谢了!
2006-04-21 12:42
柳儿
Rank: 6Rank: 6
等 级:贵宾
威 望:25
帖 子:1830
专家分:30
注 册:2004-9-23
收藏
得分:0 
楼主啊,你给的信息不全啊。
你的mytime0.h和Cpp1.cpp是放在同一个文件夹下么?

成功会使人骄傲。如果你骄傲自大,你就会停止学习。不学习,人就停止了进步
2006-04-21 12:50
linzhaoyang
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2006-4-21
收藏
得分:0 
楼上:是在一个文件夹里的,我的编译环境是vc++6.0,你可以试着把我上面给出的代码粘到你机子上试试吧!谢谢了!
这个问题困扰我好长时间了!!!
2006-04-21 14:11
lbwxqh
Rank: 1
等 级:新手上路
帖 子:28
专家分:0
注 册:2006-4-12
收藏
得分:0 
楼主好像犯了几个错误
楼主好像犯了几个错误,首选mytime0.cpp中应该用#include "mytime.h"而不是#include "mytime0.h",然后mytime0.cpp中的函数定义中operator最好能换成operator+
2006-04-22 10:36
wfpb
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:2188
专家分:0
注 册:2006-4-2
收藏
得分:0 

已经编译过了.
//mytime.h
#ifndef mytime_h
#define mytime_h

#include<iostream>
class Time
{
private:
int hours;
int minutes;
public:
Time():minutes(0),hours(0){}
Time(int h,int m=0);
void addmin(int m);
void addhr(int h){hours+=h;}
void reset(int h=0,int m=0);
Time operator+(const Time & t)const;
void show()const{std::cout<< hours<<"hours,"<<minutes<<"minutes";}
};
#endif //mytime_h

//mytime.cpp
#include"mytime.h"
Time::Time(int h,int m)
{
hours=h;
minutes=m;
}
Time Time::operator+(const Time & t)const
{
Time sum;
sum.minutes=minutes+t.minutes;
sum.hours=hours+t.hours+sum.minutes/60;
sum.minutes%=60;
return sum;
}
void Time::reset(int h,int m)
{
hours=h;
minutes=m;
}

//main.cpp
#include<iostream>
#include"mytime.h"
using namespace std;
int main()
{
Time play;
Time coding(2,40);
Time fixing(5,55);
Time total;

cout << "play time is ";
play.show();
cout << endl;

cout << "coding time is ";
coding.show();
cout << endl;

cout << "fixing time is ";
fixing.show();
cout << endl;

total=coding+fixing;
cout << "coding+fixing is ";
total.show();
cout << endl;
system("pause");
return 0;
}
建议写自己的类的时候,如果函数定义部分很少就写在类的里面,内嵌函数,节约开销.
我有个问题,不是很确定,上面的有默认参数的函数,也可以直接定义在类的里面吗?


[glow=255,red,2]wfpb的部落格[/glow] 学习成为生活的重要组成部分!
2006-04-22 13:16
linzhaoyang
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2006-4-21
收藏
得分:0 
麻烦楼上告知我你们建立文件的方法,我的方法是打开vc++6.0,然后是点击文件------新建------工程(选择win32 console application)--------文件(选择c++ source file)-------确定-------输入上面源代码。
不知道我的方法对不?请多指教!!!
谢谢
2006-04-22 18:36
快速回复:求教:程序怎么编译不了,谢谢
数据加载中...
 
   



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

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