|
如果你的日期是做成类的话,就直接写成:
class YourClass
{
int year,month,day;
public:
YourClass():year(0),month(0),day(0){}
void GetDate(char ch=' ');
void Display();
};
void YourClass::GetDate(char ch)
{
char *str=new char[5];
cin.getline(str,5,ch);
year=atoi(str);
cin.getline(str,5,ch);
month=atoi(str);
cin.getline(str,5);
day=atoi(str);
delete []str;
}
void YourClass::Display()
{
cout<<"日期:"<<year<<"年"<<month<<"月"<<day<<"日"<<endl;
}
void main()
{
YourClass s;
s.GetDate('\');
s.Display();
} |
|