c++ - 是否可以在 C++ 中禁用 stderr?

标签 c++ linux libxml2 stderr

我为 linux 编写了一个程序,使用 libxml2 进行 html 解析。虽然它完成了它的工作,但 html 解析器会向 stderr 写入许多不同的错误。是否可以完全禁用 stderr(或将其重定向到/dev/null 而不必使用重定向 shell 脚本运行它)?我可以忍受不得不将自己的错误写入标准输出,我只是想摆脱这些错误。

最佳答案

使用 freopen 重定向到 dev/null:

freopen("/dev/null", "w", stderr);

关于c++ - 是否可以在 C++ 中禁用 stderr?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/998162/

相关文章:

c++ - 将 VS2008 转换为 VS2010 项目 "cannot find the file specified"

linux - namenode端口被阻塞

c - 共享库是否使用与应用程序相同的堆?

linux - 计算 Linux 中两个模式之间的模式总数(如果可能,使用 sed)

c - libmxl2 - 改变元素的值,混合内容

c++ - 禁用 Visual Studio 绿色箭头按钮移动指令指针

c# - 监控 USB 流量

c++ - 如何在 g++ 中使用 sgi STL

c - xpath 表达式中缺失属性的默认值

iOS 64 位支持 C 框架 libxml2 "implicit conversion loses integer precision"