一个众所周知的事实是 cout 在 VS2010 中没有缓冲(参见 Stephan Lavavej 的帖子)。为什么在下面的代码中我可以使用 cout 的缓冲区构造 ostream hexout?
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
// Construct ostream hexout with cout's buffer and setup hexout to print hexadecimal numbers
ostream hexout(cout.rdbuf());
hexout.setf (ios::hex, ios::basefield);
hexout.setf (ios::showbase);
// Switch between decimal and hexadecimal output using the common buffer
hexout << "hexout: " << 32 << " ";
cout << "cout: " << 32 << " ";
hexout << "hexout: " << -1 << " " ;
cout << "cout: " << -1 << " ";
hexout << endl;
}