C + + print output pointer

Source: Internet
Author: User

You will need to print out the pointer address in many scenarios. Take a look at the following output:       CObject*Pobject =NewCObject;    STD::cout <<Pobject <<STD::Endl;  This prints out the POBJEDCT address of the pointer directly. But the output below   Char*ptr ="ABC";    STD::cout <<ptr <<STD::Endl;Direct Output string: "abc", which is why? Wait a moment.     void*pVoid =ptr;   STD::cout <<pVoid <<STD::Endl;This allows you to output the pointer address directly.  Presumably, why is it such a manifestation? Actually, it's all becauseoperator<< behavior caused by overloading. Std::cout is std::Ostream an object, in the implementation of Ostream, the string pointer is overloaded with global functions, and the prototype is implemented in VS2008:Template<class_traits>inlineBasic_ostream<Char, _traits>&__clrcall_or_cdecl operator<<(Basic_ostream<Char, _traits>&_ostr ,Const Char *_val)Other print pointers: ostream member functions:_myt&__clr_or_this_calloperator<< (Const void *_val)CObject*Pobject implicitly converts the address that the print output pointer points to

C + + print output pointer

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.