问题描述
好的,所以我有一个项目,包括返回日期值,这是一个字符串,/将月份与日期和年份分开。
因此,当日期由用户输入和/或在构造函数中声明时,它将采用MMDDYYYY格式。
IE
日期:12212000
我需要以12/21/2000格式退回
如何在头文件中实现它?我搜索和尝试过的每种语法都不起作用。所以我假设我无法计算字符串...我怎样才能转换为int?或者还有其他方法可以不计算吗?
我尝试过:
这是我的代码看起来像...
无法人口统计信息:: printDateOfBirth()
{
cout<< (dateOfBirth / 1000000)<< setprecision(2)<<固定<< /
<< ((dateOfBirth / 10000) - (100 *(dateOfBirth / 1000000)))
<< setprecision(2)<<固定<< /<< (dateOfBirth%10000)
<< setprecision(2)<<固定<< endl;
}
Ok, so I have a project that consists of returning the date value, which is a string, with "/" separating the month from day and day from year.
So when the date is either inputted by the user and/or declared in constructor, it'll be in the format MMDDYYYY.
I.E.
date: 12212000
I need to return it in this format "12/21/2000"
How can I implement that in the header file? Every syntax I've searched and tried doesn't work. So I'm assuming I cannot calculate string... how can I convert to int? Or is there another way to do this without calculation?
What I have tried:
this is what my code looks like...
void DemographicInformation::printDateOfBirth( )
{
cout << (dateOfBirth/1000000) << setprecision(2) << fixed << "/"
<< ((dateOfBirth/10000)-(100*(dateOfBirth/1000000)))
<< setprecision(2) << fixed << "/" << (dateOfBirth%10000)
<< setprecision(2) << fixed << endl;
}
这篇关于我可以将字符串转换为int,以便在C ++的头文件中实现计算吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!