格式化输出运算插入器 [英] Formatted output arithmetic inserters
问题描述
我有一个关于算术插入器的基本问题; §27.7.3.6.2 / 1 [ostream.inserters.arithmetic]:
I have a basic question about the arithmetic inserters; § 27.7.3.6.2/1 [ostream.inserters.arithmetic]:
当val类型为bool,long,unsigned long, long long,unsigned long long,double,long double或const void *,格式化转换的执行方式如同执行以下代码片段:
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()
问题是什么确切函数执行从指针到类型的转换,正如Matt McNabb更正, const void *
?例如:
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
我不关心实现细节,我只是想知道什么函数从指针产生算术结果。在上面的例子中是 put
吗?
推荐答案
从任何非指针到成员/成员函数到 void *
。在这被传递到流之后,它将它传递给 std :: num_put :: put()
,将其打印为通用指针,就像使用%p
格式标志。
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.
这篇关于格式化输出运算插入器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!