注册 登录
编程论坛 C++教室

程序分开就不行了 为什么?

winnerflyer 发布于 2008-03-15 17:19, 572 次点击
我把程序分成三块放在三个文件中,添加到工程后编译没错误,但是运行就有:
error C2143: syntax error : missing ';' before '<class-head>'
error C2871: 'std' : does not exist or is not a namespace
fatal error C1004: unexpected end of file found

//Date.h
//这是我的头文件
class Date
{
public:
    Date();
    Date(int y,int m,int d);
    void setDate(int,int,int);
    int getYear();
    int getMonth();
    int getDay();
private:
        int year;
        int month;
        int day;

};

//类date成员的定义(另一个文件)#include <iostream.h>
using namespace std
#include "Date.h"


//类的构造函数 进行初始化
Date::Date()
{
   year=month=day=0;
};

//日期值的设置函数

void Date::setDate(int y,int m,int d)
{
    year=(y>=0&&y<=12)?y:0 ;
    month=(m>=0&&m<=12)?m:0 ;
    switch(m)  ///某个月的天数的具体分析
    {
    case '1':
    case '3':
    case '5':
    case '7':
    case '8':
    case '10':
    case '12': day=(d>=0&&d<=31)?d:0; break;
    case '4':
    case '6':
    case '9':
    case '11':;day=(d>=0&&d<=30)?d:0 ; break;
        default: if(  ( (y%4==0)&&(y%100!=0) )||(y%400==0) )  //判断瑞年2月的天数是否合法
                     day=(d>=0&&d<=29)?d:0 ;
               else  day=(d>=0&&d<=28)?d:0 ;
                break;
    }


    
    
}

//日期值的输出函数
int Date::getYear()
{
    return year;
}


int Date::getMonth()
{
    return month;
}


int Date::getDay()
{
    return day;
}

//我的main文件
#include <iostream.h>
#include "Date.h"
//using namespace std;

void main()
{
    Date d;
    cout<<"原始时间是(年-月-日的方式输出):"<<d.getYear()<<"-"<<d.getMonth()<<"-"<<d.getDay()<<endl;

    d.setDate(1,5,31);

    cout<<"合法修正后的时间输出是:"<<d.getYear()<<"-"<<d.getMonth()<<"-"<<d.getDay()<<endl;

}
3 回复
#2
sunkaidong2008-03-15 18:25
//类date成员的定义(另一个文件)#include <iostream.h>
//using namespace std  把命名空间去了....就对了..
#include "Date.h"
#3
sunkaidong2008-03-15 18:26
你看看关于命名空间吧...我知道java和c#里面比较强调这个概念..c还没太注意
#4
winnerflyer2008-03-15 18:52
谢了!
上网看了命名空间 似乎明白点了
1