cout<< cout和cout<<& cout在c ++中有什么区别? [英] What's the difference between cout<<cout and cout<<&cout in c++?

查看:187
本文介绍了cout<< cout和cout<<& cout在c ++中有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个初学者问题,了解cout如何工作可能是关键。如果有人可以链接到一个很好的解释,这将是巨大的。
cout<< cout cout<<& cout 一个linux x86机器。

This might be a beginner question and understanding how cout works is probably key here. If somebody could link to a good explanation, it would be great. cout<<cout and cout<<&cout print hex values separated by 4 on a linux x86 machine.

推荐答案

cout< cout 等效于 cout<< cout.operator void *()。这是在C ++ 11之前用于确定iostream是否处于故障状态,并在 std :: ios_base 中实现的习语;它通常返回 static_cast< std :: ios_base *>(& cout)的地址。

cout << cout is equivalent to cout << cout.operator void *(). This is the idiom used before C++11 to determine if an iostream is in a failure state, and is implemented in std::ios_base; it usually returns the address of static_cast<std::ios_base *>(&cout).

cout< & cout 打印出 cout 的地址。

c> std :: ios_base 是 cout 的虚拟基类,它不一定与 cout 。这就是为什么它打印一个不同的地址。

Since std::ios_base is a virtual base class of cout, it may not necessarily be contiguous with cout. That is why it prints a different address.

这篇关于cout&lt;&lt; cout和cout&lt;&lt;&amp; cout在c ++中有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆