#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main()
{
ofstream out("out.txt");
ofstream err("err.txt");
ofstream log("log.txt");

cout.rdbuf(out.rdbuf());//重定向cout 到 out.txt
cerr.rdbuf(err.rdbuf());//重定向cerr 到 err.txt
clog.rdbuf(log.rdbuf());//重定向clog 到 log.txt

cout<<"cout test"<<endl;
cerr<<"cerr test"<<endl;
clog<<"clog test"<<endl;
return 0;
}
//Use cout for the standard output. buffered
//Use cerr to show errors. unbuffered
//Use clog for logging. buffered

cin也可以重新到文件,从文件输入。