郁闷!!!!编译器说我的 std 不是 namespace! 你说气人不气人
各位论坛朋友,,我弄了个简单的程序,,编译就是不能通过.不是说我的std不是名字空间,就是说我的cout 没有定义.
哪位知道的,,希望能指点一下,,多谢!
//mytime.h--头文件 包含Time类
#ifndef MY_TIME_H_
#define MY_TIME_H_
class Time
{
public:
Time();
Time(int h, int m=0);
void AddMinutes(int m);
void AddHours(int h);
void Show();
void Reset(int h=0, int m=0);
Time operator+(const Time &t) const;
Time operator-(const Time &t)const;
Time operator*(double n)const;
friend Time operator*(double n, const Time &t)
{
return t*n;
}
//friend std::ostream & operator<<(std::ostream &os, const Time &t);
private:
int hours;
int minutes;
};
#endif
//mytime.cpp--Time 类的实现
#include "mytime.h"
Time::Time()
{
hours=minutes=0;
}
Time::Time(int h, int m)
{
hours=h;
minutes=m;
}
void Time::AddHours(int h)
{
hours+=h;
}
void Time::AddMinutes(int m)
{
minutes+=m;
hours+=minutes/60;
minutes%=60;
}
void Time::Reset(int h, int m)
{
hours=0;
minutes=0;
}
void Time::Show()
{
cout << hours << ":" << minutes;
}
Time Time::operator +(const Time &t) const
{
Time sum;
sum.minutes=minutes+t.minutes+hours*60;
sum.hours=sum.minutes/60;
sum.minutes%=60;
return sum;
}
Time Time::operator -(const Time &t) const
{
Time diff;
int total_1,total_2;
total_1=minutes+hours*60;
total_2=t.minutes+t.hours*60;
diff.hours=(total_1-total_2)/60;
diff.minutes=(total_1-total_2)%60;
return diff;
}
Time Time::operator*(double n) const
{
Time result;
long totalMinutes=hours*n*60+minutes*60;
result.hours=totalMinutes/60;
result.minutes=totalMinutes%60;
return result;
}
//usemytime.cpp--主函数
#include <iostream>
#include "mytime.h"
using namespace std;
int main(void)
{
Time tobj_1(5,36);
Time tobj_2(3,30);
Time temp;
tobj_1.Show();
tobj_2.Show();
temp=tobj_1+tobj_2;
temp.Show();
temp=tobj_1-tobj_2;
temp.Show();
return 0;
}
哪位用的C++ 7.0以上版本的话,帮忙编译一下,看能否通过.兄弟我穷,内存装不起高版本的.