date_02.cpp
来自「数据结构常用算法合集」· C++ 代码 · 共 33 行
CPP
33 行
//date_02.cpp
#include <iostream.h> //cin,cout
#include <conio.h> //getch()
#include <dos.h> //getdate(),setdate()
/********************************************/
//struct date 内建date结构
//{ int da_year;
// char da_day; 需转为整数类型
// char da_mon;};
// void getdate(date *); 内建函数 取得日期
// void setdate(date *); 内建函数 设定日期
/*******************************************/
void main()
{ date today;
short mon,day;
cout <<"今天日期为:\n";
getdate(&today); //取得日期
cout << today.da_year <<" 年 "
<< (short)today.da_mon <<" 月 "
<< (short)today.da_day <<" 日\n";
cout <<"输入要更改的年月日:";
cin >> today.da_year >> mon >> day;
today.da_mon = char(mon); //转为字符
today.da_day = char(day);
setdate(&today); //设定日期
getdate(&today); //再取得日期
cout <<"设定后日期为:";
cout << today.da_year <<" 年 "
<< (short)today.da_mon <<" 月 "
<< (short)today.da_day <<" 日\n";
getch();
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?