Reputation: 111
I want to show current date and time in my c++ program. I did this simply by these lines of code:
char date[9], time[9];
_strdate( date );
_strtime( time );
cout << "Current date and time: " << date << " " << time << endl;
This perfectly worked in MS Visual C++ 2010 and Dev C++ 4.9.9.2. But this doesn't work in Xcode! It says that I'm using undeclared identifiers 'strdate' and 'strtime'. I have included iostream and ctime libraries, but this didn't help. What's the problem? Thanks in advance.
Upvotes: 0
Views: 1819
Reputation: 8390
std::string _strdate_alternative()
{
char cptime[50];
time_t now = time(NULL);
strftime(cptime, 50, "%b. %d, %Y", localtime(&now)); //short month name
return std::string(cptime);
}
As said before, there is no such function in standard c/c++ library. You can use this alternative. Code is based on some info found on the Internet. I didn't compile it.
Upvotes: 1
Reputation: 10096
These functions are not part of standard C++; they are Microsoft-specific extensions, and thus may not be available everywhere.
For similar functionality, you may try combining time
, localtime
and strftime
.
Upvotes: 1