小编Cha*_*arx的帖子

C++:重定向STDOUT

在我的应用程序中,我想将通常转到stdout流的输出重定向到我定义的函数.我读到你可以将stdio重定向到一个文件,为什么不用一个函数呢?

例如:

void MyHandler( const char* data );

//<<Magical redirection code>>

printf( "test" );
std::cout << "test" << std::endl;

//MyHandler should have been called with "test" twice, at this point
Run Code Online (Sandbox Code Playgroud)
  • 我怎样才能实现这种/类似的行为?

c++

48
推荐指数
5
解决办法
5万
查看次数

标签 统计

c++ ×1