I know I can do it this way. But are there better ways to do that?Code:#include <iostream> int main() { char *ch = "123"; std::cout << static_cast<void *>(ch); return 0; }
I know I can do it this way. But are there better ways to do that?Code:#include <iostream> int main() { char *ch = "123"; std::cout << static_cast<void *>(ch); return 0; }
No. and If you consider how often you'll need to be printing pointer values it shoudln't really bother you.
Instead of using the C++ hammer, you can use the hammer that comes from C ....
This is functionally equivalent in this case, but a little terser. If that meets your definition of "better", go for it.Code:#include <iostream> int main() { char *ch = "123"; std::cout << ((void *)ch); return 0; }
No. Sure I don't think less typing is better.
Thanks guys~~ :-)
maybe not "better" but "different"
Code:#include <iostream> int main() { char *ch = "123"; printf("%p\n",ch); return 0; }
Sure I know it. That's why I wrote "using cout" at the title
[rant]printf() is about as simple as it can be done. cout (and all of iostreams/fstream c++ library) is just plain-old ugly, overly-complicated and horribly implemented. I refuse to use it in all but the simplest cases. [/rant] But that doesn't answer your question
I agree. Why would you use a type-safe and extensible library when you can use some lovely vararg function that is the cause of more buffer overflows and security loopholes then you can count?Originally Posted by Ancient Dragon