Formatted output arithmetic inserters

泄露秘密 提交于 2019-12-13 21:52:24

问题


I have a basic question about the arithmetic inserters; § 27.7.3.6.2/1 [ostream.inserters.arithmetic]:

When val is of type bool, long, unsigned long, long long, unsigned long long, double, long double, or const void*, the formatting conversion occurs as if it performed the following code fragment:

bool failed = use_facet<
  num_put<charT,ostreambuf_iterator<charT,traits> >
    > (getloc()).put(*this, *this, fill(), val).failed()

The question is what exact function performs the conversion from a pointer to type to, as Matt McNabb corrected, const void*? For instance:

int *ip = new int(1);
std::cout << ip; //0xaa33fa67

I'm not concerned in an implementation details, I just would like to know what function produces arithmetic result from the pointer. Is it put in the example above?


回答1:


There's an implicit coversion from any non-pointer to member/member function to void*. After this is passed to the stream, it passes it off to std::num_put::put() which prints it out as a generic pointer as if by using the "%p" format flag.



来源:https://stackoverflow.com/questions/26210379/formatted-output-arithmetic-inserters

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!