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

关于头文件的一个小问题,高手进来下…………

a632034079 发布于 2010-08-10 11:24, 448 次点击
为什么下面的代码用#include <iostream> using namespace std;就不不能通过编译,而用#include <iostream.h>却可以???这两个头文件的不是同样的意思吗???他们有什么区别吗???


include <iostream.h>

class shijian
{
private:
public:
    int year;
    int month;
    int day;
public:
    friend ostream& operator<<(ostream& output,shijian &sj);
    friend istream& operator>>(istream& input,shijian &x);
};

ostream& operator<<(ostream &output,shijian &sj)
{
    output << sj.year << "/" << sj.month << "/" << sj.day << endl;
    return output;
}

istream& operator>>(istream& input,shijian &x)
{
    input >> x.year >> x.month >> x.day;
    return input;
}

int main()
{
    shijian a;
    cin>>a;
    cout<<a;

    return 0;;
}
4 回复
#2
towhee2010-08-10 17:38
程序代码:

#include <iostream>
using namespace std;
class shijian
{
private:
public:
    int year;
    int month;
    int day;
public:
    friend ostream& operator<<(ostream& output,shijian &sj);
    friend istream& operator>>(istream& input,shijian &x);
};

ostream& operator<<(ostream &output,shijian &sj)
{
    output << sj.year << "/" << sj.month << "/" << sj.day << endl;
    return output;
}

istream& operator>>(istream& input,shijian &x)
{
    input >> x.year >> x.month >> x.day;
    return input;
}

int main()
{
    shijian a;
    cin>>a;
    cout<<a;

    return 0;;
}

以上代码编译通过,环境vs2005+xp
#3
towhee2010-08-10 18:10
程序代码:

#include <iostream>
using namespace std;
class shijian
{
private:
public:
    int year;
    int month;
    int day;
public:
    friend ostream& operator<<(ostream& output,shijian &sj);
    friend istream& operator>>(istream& input,shijian &x);
};

ostream& operator<<(ostream &output,shijian &sj)
{
    output << sj.year << "/" << sj.month << "/" << sj.day << endl;
    return output;
}

istream& operator>>(istream& input,shijian &x)
{
    input >> x.year >> x.month >> x.day;
    return input;
}

int main()
{
    shijian a;
    cin>>a;
    cout<<a;

    return 0;;
}

以上代码编译通过,环境vs2005+xp
#4
a6320340792010-08-11 07:32
以下是引用towhee在2010-8-10 18:10:22的发言:


#include <iostream>
using namespace std;
class shijian
{
private:
public:
    int year;
    int month;
    int day;
public:
    friend ostream& operator<<(ostream& output,shijian &sj);
    friend istream& operator>>(istream& input,shijian &x);
};

ostream& operator<<(ostream &output,shijian &sj)
{
    output << sj.year << "/" << sj.month << "/" << sj.day << endl;
    return output;
}

istream& operator>>(istream& input,shijian &x)
{
    input >> x.year >> x.month >> x.day;
    return input;
}

int main()
{
    shijian a;
    cin>>a;
    cout<<a;

    return 0;;
}

以上代码编译通过,环境vs2005+xp



VC++6.0不能通过………………
#5
pangding2010-08-11 09:39
编译报的错是什么?
1