【发布时间】:2012-08-18 17:44:01
【问题描述】:
我的输出是不可读的,我想做的就是将日月年分配到一个字符串中。
如果我通过 now->tm_year+1900 计算它们,它可以工作,但如果我将它分配给一个字符串并稍后 cout,它会像这样输出。如何更改我的代码,以便我可以将值分配给字符串,而不会在以后丢失 cout 的引用。
终端:
Date is
我的代码:
int main()
{
//get today date
string year,month,day;
/* Output 6 month frame for appointment booking*/
time_t t = time(0); // get time now
struct tm * now = localtime( & t );
year = now->tm_year + 1900;
month = now->tm_mon + 1;
day = now->tm_mday;
cout << "Date is " << year << month << day << endl;
return 0;
}
【问题讨论】:
标签: c++