#define
.
.
#endif
要怎么用啊 小弟到现在都没弄明白啊
#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++啊
[此贴子已经被作者于2006-7-16 22:15:29编辑过]
问题出在你对头文件的命名上
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;
}
//////////////////
//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;
}