W
White Wolf
Mike Wahler wrote:
[SNIP]
And it is still a pure C solution. IIRC there was an agreement here that
when showing code, we show C++ code and the best C++ there is to demonstrate
the issue. I see no problem with pure C code as long as it is proven that
that piece of code is the best C++ solution as well.
[SNIP]
You can do it the same way in C, C++, VC++, gcc, g++, in fact in any C
or C++ compiler in the world.
#include <time.h>
#include <stdio.h>
time_t t = time(0);
struct tm* lt = localtime(&t);
char time_str[15];
sprintf(time_str, "%04d%02d%02d%02d%02d%02d",
lt->tm_year + 1900, lt->tm_mon + 1, lt->tm_mday,
lt->tm_hour, lt->tm_min, lt->tm_sec);
Untested code
Which part of the above is C++?
All of it. Remember that the C++ standard library contains
the (C90) C standard library. Also, tHe headers with .h, while
deprecated, are indeed part of standard C++.
And it is still a pure C solution. IIRC there was an agreement here that
when showing code, we show C++ code and the best C++ there is to demonstrate
the issue. I see no problem with pure C code as long as it is proven that
that piece of code is the best C++ solution as well.