【发布时间】:2012-12-04 16:21:49
【问题描述】:
我有以下sn-p的代码:
time_t data1 = time(0)+86400;
struct tm * data_emprestimo = localtime( & data1 );
cout << "Hoje: " << data_emprestimo->tm_mday << '/' << (data_emprestimo->tm_mon + 1) << '/' << (data_emprestimo->tm_year + 1900) << endl;
效果很好。
但我想知道我应该在函数中返回什么类型来获取 cout 回显并放入变量:struct tm?只是tm?大批?字符串?
我尝试过这样的事情:
struct tm retornaData(int segundosAdd);
...
...
struct tm retornaData(int segundosAdd){
return data_emprestimo;
}
但它不起作用。
我已经用谷歌搜索了很多!
【问题讨论】:
-
你想得到
data_emprestimo->tm_mday? -
我想要这个返回格式 -> '2012-12-17'
-
你真的应该把它翻译成英文。现在可读性降低了。
-
返回
struct something是面向 C 的,C++ 不太一样。你应该先学习 C++ ;) -
skp,你看我的问题了吗? “我是 C++ 的初学者……”