Suppress output to cout from linked library

后端 未结 6 1128
感情败类
感情败类 2020-12-31 19:49

I need to link my C++ programs against a couple shared libraries which generate way too much output to std::cout and std::cerr rendering them both

6条回答
  •  生来不讨喜
    2020-12-31 20:42

    If you don't need to use either yourself, the easiest thing to do would be to just redirect standard output and standard error from the command line when you start your program.

    $ myprog >/dev/null 2>&1

    If you do want to use them yourself, the trick would be to change the streambuf they use. There's some code and discussion about how to do that here. Its really too long to post here.

提交回复
热议问题