找回密码
 注册
搜索
热搜: 回贴
  • 前程无忧官网首页 有什么好的平台可以
  • 最新的销售平台 互联网营销的平台有哪
  • 制作网页的基本流程 网页制作和网页设
  • 【帝国CMS】输出带序号的列表(数字排
  • 网站建设公司 三一,中联,极东泵车的
  • 织梦 建站 织梦网站模版后台怎么更改
  • 云服务官网 哪些网站有免费的简历模板
  • 如何建网站要什么条件 建网站要用什么
  • 吉林市移动公司电话 吉林省退休人员网
  • 设计类毕业论文 网站设计与实现毕业论
查看: 617|回复: 9

[求助]关于头文件的问题

[复制链接]
发表于 2009-11-3 03:49:48 | 显示全部楼层 |阅读模式 IP:江苏扬州
对于 #ifndef
#define
.
.
#endif

要怎么用啊 小弟到现在都没弄明白啊
发表于 2009-11-3 03:49:50 | 显示全部楼层 IP:江苏扬州
这个不需要太掌握吧....头文件卫士以后的趋势是渐渐淡出了。...
回复

使用道具 举报

发表于 2009-11-3 03:49:51 | 显示全部楼层 IP:江苏扬州
我现在看的这本书是这么写的啊 但是我不知道怎么用啊 编译都通不过
回复

使用道具 举报

发表于 2009-11-3 03:49:53 | 显示全部楼层 IP:江苏扬州
#ifndef 宏名//如果宏没有被定义过
执行程序段...
回复

使用道具 举报

发表于 2009-11-3 03:49:55 | 显示全部楼层 IP:江苏扬州
这我是知道  但是为什么编译通不过呢
回复

使用道具 举报

发表于 2009-11-3 03:49:56 | 显示全部楼层 IP:江苏扬州
代码帖一部分上来,还有错误提示是什么?
回复

使用道具 举报

发表于 2009-11-3 03:49:57 | 显示全部楼层 IP:江苏扬州
#ifndef time_h
#define time_h
class time{
public:
time();
void settime(int,int,int);
void printmilitary();
private:
int hour;
int minute;
int second;
};
#endif

#include <iostream.h>
#include "time.h"
time::time()
{hour=minute=second=0;}
void time::settime(int h,int m,int s)
{
hour = (h>=0&&h<24)?h:0;
minute = (m>=0&&m<60)?m:0;
second = (s>=0&&s<60)?s:0;
}
void time::printmilitary()
{
cout<<(hour<10?"0":"")<<hour<<":"<<(minute<10?"0":"")<<minute;
}
#include <iostream.h>
#include "time.h"
int main()
{
time t;
t.printmilitary();

t.settime(13,27,6);
t.printmilitary();
return 0;
}



他提示是划线的地方错

错误提示是: statement missing ;
undefined symbol 't'



我用的是tc++啊
回复

使用道具 举报

发表于 2009-11-3 03:49:58 | 显示全部楼层 IP:江苏扬州
问题出在你对头文件的命名上
time.h和C++原有的头文件重名了

#ifndef time_h
#define time_h
class Time{
public:
Time();
void settime(int,int,int);
void printmilitary();
private:
int hour;
int minute;
int second;
};
#endif

#include <iostream>
#include "Time.h"
using namespace std;
Time::Time()
{hour=minute=second=0;}
void Time::settime(int h,int m,int s)
{
hour = (h>=0&&h<24)?h:0;
minute = (m>=0&&m<60)?m:0;
second = (s>=0&&s<60)?s:0;
}
void Time::printmilitary()
{
cout<<(hour<10?"0":"")<<hour<<":"<<(minute<10?"0":"")<<minute;
}

#include <iostream>
#include "Time.h"
using namespace std;
int main()
{
Time t;
t.printmilitary();
t.settime(13,27,6);
t.printmilitary();
return 0;
}
回复

使用道具 举报

发表于 2009-11-3 03:49:59 | 显示全部楼层 IP:江苏扬州
可是当我把头文件名给改了以后,它显示找不到这个头文件啊
回复

使用道具 举报

发表于 2009-11-3 03:50:04 | 显示全部楼层 IP:江苏扬州
//////////////////
//Time.h
/////////////////
#ifndef time_h
#define time_h
class Time{
public:
Time();
void settime(int,int,int);
void printmilitary();
private:
int hour;
int minute;
int second;
};
#endif
//////////////////////////
//Time.cpp
//////////////////////////
#include <iostream>
#include "Time.h"
using namespace std;
Time::Time()
{hour=minute=second=0;}
void Time::settime(int h,int m,int s)
{
hour = (h>=0&&h<24)?h:0;
minute = (m>=0&&m<60)?m:0;
second = (s>=0&&s<60)?s:0;
}
void Time::printmilitary()
{
cout<<(hour<10?"0":"")<<hour<<":"<<(minute<10?"0":"")<<minute;
}


//////////////////
//main.cpp
/////////////////
#include <iostream>
#include "Time.h"
using namespace std;
int main()
{
Time t;
t.printmilitary();
t.settime(13,27,6);
t.printmilitary();
return 0;
}
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|小黑屋|最新主题|手机版|微赢网络技术论坛 ( 苏ICP备08020429号 )

GMT+8, 2024-9-30 15:19 , Processed in 0.410166 second(s), 13 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表