当我在VS中运行此代码时:
#include <iostream>
#include <sstream>
using namespace std;
int main(int args, char *argv[])
{
ostringstream local;
auto cout_buff = cout.rdbuf();
cout.rdbuf(local.rdbuf());
cout << "some message";
cout.rdbuf(cout_buff);
cout << "back to default buffer\n";
cout << "local contetn:" << local.str() << endl;
}
我想了解cout
的内部变化,试图在 Watch Window 中添加cout
,但是我得到了identifier "cout" is undefined
。怎么会来?
答案 0 :(得分:3)
我不得不推测为什么找不到cout
,但这是创建本地别名和 watch 的解决方法:>
int main(int args, char *argv[])
{
auto& cout = std::cout;
// ...