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

书上没说清楚,求指教错误

原味好 发布于 2011-12-09 19:33, 736 次点击
编程环境:visual c++ 6.0
两个文件为什么连不起来??
程序代码:
文件1
# include<iostream.h>
# include"tdate.h"

void main()
{
    Tdate s;
    s.Set(12/9/2011);
    someFunc(&s);
}
void someFunc(Tdate * pS)
{
    pS->Print();
    if (pS->IsLeapYear())
        cout<<"ohoh\n";
    else
        cout<<"right\n";
}
文件2
# include<iostream.h>
class Tdate
{
public:
    void Set(int m,int d,int y)
    {
        month=m;
        day=d;
        year=y;
    }
    int IsLeapYear()
    {
        return (year%4==0&&year%100!=0)||(year%400==0);
    }
    void Print()
    {
        cout<<month<<"/"<<day<<"/"<<year<<"\n";
    }
private:
    int month;
    int day;
    int year;
};   
错误提示:
C:\Users\Administrator\Desktop\c++\2.cpp(2) : fatal error C1083: Cannot open include file: 'tdate.h': No such file or directory
4 回复
#2
rjsp2011-12-10 08:16
错误提示已经非常直白明了了
#3
共和国鹰派2011-12-10 17:48
第二个文件你是命名为tdate.h的吗?并且你的代码中也有错误啊,cout没有加上命名空间啊
#4
lonely_212011-12-11 00:26
主函数中调用void someFunc(Tdate * pS)时要在调用之前声明
主函数中s.Set(12/9/2011);应写成s.Set(12,9,2011);
#5
wsgzg2011-12-22 22:13
“tdate.h”是楼主自己写的头文件吧!需要设置编译器环境。。。
1