As we all know, if for some reason you printf()
something rather than stream it (which rarely, but sometimes, might happen), you need to specify an appropriate format specifier (d
for signed int, u
for unsigned, etc. etc.). Now, since printf()
is part of the C++ standard library and not just some C legacy, I would hope there might be something like
template <typename T>
const std::string format_specifier;
Which would allow, say:
template <typename Foo>
void bar(const Foo& my_foo) {
printf(format_specifier<Foo>, my_foo);
}
Does the standard library contain something like that?
Notes:
std::cout
, of course that's the default thing you should do. I asked about a function that's part of the standard library; if it were removed from it you could say "this should never ever be used, so your question doesn't matter".I originally wrote this as a comment, since it seemed too short.
The short answer is "no", since the C++ standard does not specify any such facilities.
Given properties of functions that are inherited from the C standard library for reasons of backward compatibility (no overloading, permitted in both the global namespace and namespace std, etc), and the way that using C++ iostream
classes is encouraged, I would be surprised if such a feature ever comes to be standardised.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With