【问题标题】:How can i disable/ignore cerr output stream in JetBrains CLion?如何在 JetBrains CLion 中禁用/忽略 cerr 输出流?
【发布时间】:2016-03-02 05:58:16
【问题描述】:

我有一个工具,可以产生许多 cerr 输出。
如果我通过 Clion 中的“运行配置”运行它,我会在输出窗口中看到所有 cerr 消息。
如何在 Clion/Intellij 中禁用某些输出流?
我使用的是 Windows 10。

【问题讨论】:

    标签: c++ outputstream clion jetbrains-ide


    【解决方案1】:

    您应该将 cerr 输出重定向到一个文件。

    #include <iostream>
    #include <fstream>
    #include <string>
    
    int main()
    {
        std::ofstream output("output.txt");
        std::streambuf* p_cerrbuffer=std::cerr.rdbuf();
        std::cerr.rdbuf(output.rdbuf()); // redirecting to a file
    
        std::cout<<"cout"<<std::endl; // "cout" appears on the standard output.
        std::cerr<<"cerr"<<std::endl; // "cerr" appears in the output.txt file
    }
    

    【讨论】:

    • 我很肤浅。我很抱歉!不幸的是,我不了解 JetBrains CLion。如果您从命令提示符在 Windows 上运行应用程序,那么以下语句可能会对您有所帮助:“applivcation.exe 2>file.txt”。按 Enter 键,cerr 输出将重定向到 file.txt。这个语句也创建了file.txt,你不必自己做。
    猜你喜欢
    • 2011-10-29
    • 2021-03-22
    • 2023-03-10
    • 2020-12-30
    • 1970-01-01
    • 2014-07-31
    • 1970-01-01
    • 2012-10-13
    • 1970-01-01
    相关资源
    最近更新 更多