You can always use the standard error stream for e.g. error messages.
#include <iostream>
using namespace std;
int main() {
cout << "Redirect to file1" << endl;
cerr << "Redirect to file2" << endl;
}
For example, using the Windows [cmd.exe] command interpreter, and the Visual C++ cl
compiler:
[D:\dev\test] > type con >streams.cpp #include <iostream> using namespace std; int main() { cout << "Redirect to file1" << endl; cerr << "Redirect to file2" << endl; } ^Z [D:\dev\test] > cl streams.cpp streams.cpp [D:\dev\test] > streams 1>a.txt 2>b.txt [D:\dev\test] > type a.txt Redirect to file1 [D:\dev\test] > type b.txt Redirect to file2 [D:\dev\test] > _
EDIT: added colorized code and boldface emphasis.