Code:
#include <iostream>
using namespace std;

int main ( ) {
  cout << "hello ";
  cerr << "this is an error"; // appears before hello if cout isn't flushed
  cout << "world" << endl;
  return 0;
}
If run without any redirection, we get
$ ./a.exe
this is an errorhello world

Redirecting stdout, we only see stderr on console
$ a.exe 1> f1.txt
this is an error

Redirecting stderr, we only see stdout on console
$ a.exe 2> f2.txt
hello world