2015-11-28 14 views

回答

0

你应该重定向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 
} 
+0

我的意思是不在代码中,但在IDE本身。 –

+0

我肤浅。对不起!不幸的是我不知道JetBrains CLion。如果您从命令promt在Windows上运行应用程序,则以下语句可能会对您有所帮助:“applivcation.exe 2> file.txt”。按Enter键,cerr输出将重定向到file.txt。这个声明也创建了file.txt,你不必亲自去做。 –