开发者

How can I check in C++ whether std::cout is redirected to a file?

I need my program to behave differently, depending on whether the output is to a terminal or to a file. How can I find this out from within C++?

I assume there is no solution that works for all operating systems. For my purposes, it would be good to have one strategy which works under Windows and one which w开发者_JAVA百科orks under linux/unix.

Thanks in advance.


This will help under linux: How to tell if running in a linux console versus an ssh session?

Yes it is a C call, but it can definitely be called from C++.

GetStdHandle gives a similar starting point under windows:

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜