It's implementation defined if that works or not.
The implementation may include additional headers it needs, but you as a developer should not rely on that and include cstdio
too which is the guaranteed way to get access to std::printf
.
Including stdio.h
puts printf
in the global namespace and that is usually not what one wants in C++, so stick with cstdio
.
It appears your implementation puts printf
in the global namespace even though you've only included a C++ header. That's unfortunate, but that happens too.
Evidence: My preprocessor is called cpp
and I can use it to list the included header files. I have this program that I've called std.cpp
:
#include <iostream>
int main() {}
and if I use cpp
to list a small subset of the included headers
cpp -M std.cpp | tr -d '\\' | tr ' ' '\n' | \
grep -E '^/[^\.]+$' | awk -F/ '{print $NF}'
I get these C++ headers on my system:
iostream
ostream
ios
iosfwd
cwchar
exception
typeinfo
new
type_traits
cstdint
clocale
cctype
string
initializer_list
cstdlib
cstdio
cerrno
system_error
stdexcept
streambuf
cwctype
istream
and yes, cstdio
is in there which also includes stdio.h
.