| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 572 人关注过本帖
标题:程序分开就不行了 为什么?
只看楼主 加入收藏
winnerflyer
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2008-3-14
收藏
 问题点数:0 回复次数:3 
程序分开就不行了 为什么?
我把程序分成三块放在三个文件中,添加到工程后编译没错误,但是运行就有:
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;

}
搜索更多相关主题的帖子: unexpected private public before 
2008-03-15 17:19
sunkaidong
Rank: 4
来 自:南京师范大学
等 级:贵宾
威 望:12
帖 子:4496
专家分:141
注 册:2006-12-28
收藏
得分:0 
//类date成员的定义(另一个文件)#include <iostream.h>
//using namespace std  把命名空间去了....就对了..
#include "Date.h"

学习需要安静。。海盗要重新来过。。
2008-03-15 18:25
sunkaidong
Rank: 4
来 自:南京师范大学
等 级:贵宾
威 望:12
帖 子:4496
专家分:141
注 册:2006-12-28
收藏
得分:0 
你看看关于命名空间吧...我知道java和c#里面比较强调这个概念..c还没太注意

学习需要安静。。海盗要重新来过。。
2008-03-15 18:26
winnerflyer
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2008-3-14
收藏
得分:0 
谢了!
上网看了命名空间 似乎明白点了
2008-03-15 18:52
快速回复:程序分开就不行了 为什么?
数据加载中...
 
   



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

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