cpp05.cpp

来自「C++参考书」· C++ 代码 · 共 43 行

CPP
43
字号

// Coded by plusir -- Dec.30.2002.
// Standard C++ Bible -- (P283-11-5)

#include <iostream>
#include <ctime>
using namespace std ;

class Date
{
	public:
		Date( time_t ) ;
		void display( void ) const ;

	private:
		int month ;
		int day ;
		int year ;
} ;

Date::Date( time_t now )
{
	tm *tim = localtime( &now ) ;

	day = tim->tm_mday ;
	month = tim->tm_mon + 1 ;
	year = tim->tm_year + 1900 ;
}

void Date::display( void ) const
{
	cout << month << '/' << day << '/' << year << endl ;
}

int main()
{
	time_t now = time( NULL ) ;
	Date dt( now ) ;
	dt.display() ;

	return 0 ;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?