To be precise, the C++ <ctime> header brings the symbols from the C
<time.h> header into namespace std, and possibly also places them in the
global namespace. The C++ <time.h> header (in C++14 specified in §D.5/2)
brings the namespace std symbols from <ctime> into the global namespace,
possibly without providing the names in namespace std...
The C++14 standard gives this example in D5:
"The header <cstdlib> assuredly provides its declarations and
definitions within the namespace std. It may also provide these names
within the global namespace. The header <stdlib.h> assuredly provides
the same declarations and definitions within the global namespace, much
as in the C Standard. It may also provide these names within the
namespace std."
The upshot is that code that includes e.g. <ctime> may work with one
compiler when using an unqualified name, but may fail to compile with
some other compiler, both standard-conforming.
Code that includes <time.h> and uses std-qualified names may likewise be
non-portable, but it's less likely that <time.h>-based code qualifies
names than that <ctime>-based code doesn't qualify names, and it's less
likely that <time.h> places names in namespace std than that <ctime> or
some other other header places names in the global namespace.
Multiplying those less-likelies it's much less likely overall.
And so, the chance of inadvertently writing non-portable code is
minimized by using the ".h" headers. It also yields less verbose code.
And it teaches one to generally avoid using the names defined by the C
library, for other things, i.e. treating them as reserved names.
Cheers,
- Alf
--
Using Thunderbird as Usenet client, Eternal September as NNTP server.