方法一:利用istream
#include<iostream>
using namespace std;
class Date
{
private:
int d,m,y;
public:
Date(istream &in);
};
int main()
{
Date my_date(cin);
my_date.show();
}
Date::Date(istream &in)
{
in >> y >> m >> d;
}
方法二:直接利用cin输入
#include<iostream>
using namespace std;
class Date
{
private:
int d,m,y;
public:
Date();
void show()const;
};
int main()
{
Date my_date;
my_date.show();
}
Date::Date()
{
int a,b,c;
cin >> a >> b >> c;
y = a;
m = b;
d = c;
}
void Date::show()const
{
cout << Date::d << endl;
}