你可以用
getch()试试
很奇怪,如果用getch()的话,输出结果也只有
Dateobject initialized.
2001/10/1
很奇怪,如果用getch()的话,输出结果也只有
Dateobject initialized.
2001/10/1
如:
#include <conio.h>
#include <ctype.h>
int main( void )
{
int ch;
_cputs( "Type 'Y' when finished typing keys: " );
do
{
ch = _getch();
ch = toupper( ch );
} while( ch != 'Y' );
_putch( ch );
_putch( '\r' ); // Carriage return
_putch( '\n' ); // Line feed
}
[此贴子已经被作者于2007-3-13 23:28:25编辑过]
#include <cstdlib>
#include <iostream>
#include <stdio.h>
using namespace std;
class Date
{
public:
Date ();
~Date ();
void SetDate(int y,int m,int d);
int IsLeapYear()const;
void PrintDate()const;
private:
int year,month,day;
};
Date:: Date () //构造函数
{cout<<"Date object initialized.\n";
}
Date:: ~ Date() //析构函数
{cout<<"Date object destroyed.\n";
system("PAUSE");//在此加入该语句;
}
void Date:: SetDate(int y, int m, int d)
{year=y;month=m;day=d;}
int Date:: IsLeapYear() const
{
return(year%4==0&&year%100!=0)||(year%400==0);
}
void Date:: PrintDate() const
{cout<<year<<"/"<<month<<"/"<<day<<endl;}
int main(int argc, char *argv[])
{
Date d;
d.SetDate(2001,10,1);
d.PrintDate();
system("PAUSE");
return EXIT_SUCCESS;
}