如何在没有硬编码到C ++头文件的情况下编码当前年份? [英] How do you code the current year without hard coding it to header file in C++?

查看:85
本文介绍了如何在没有硬编码到C ++头文件的情况下编码当前年份?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

寻找可以返回和计算的代码,以查找人的当前年龄,而无需在头文件中对年份进行硬编码。



我有什么尝试过:



这个有效,但是我的导师说今年没有硬编码...



int DemographicInformation :: getAge()

{

return(2016 - (dateOfBirth%10000));

}

Looking for code that can be returned and calculated to find a person's current age without hard coding the year in the header file.

What I have tried:

this works but my instructor said to not hard code the year...

int DemographicInformation::getAge( )
{
return (2016 - (dateOfBirth%10000));
}

推荐答案

检查一下: C ++日期和时间 [< a href =https://www.tutorialspoint.com/cplusplus/cpp_date_time.htmtarget =_ blanktitle =New Window> ^ ]


这篇关于如何在没有硬编码到C ++头文件的情况下编码当前年份?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆