Code:
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
FILE *LaunchLogWindow()
{
char *name = tempnam(NULL, NULL);
char cmd[256];
mkfifo(name, 0777);
if(fork() == 0)
{
sprintf(cmd, "xterm -e cat %s", name);
system(cmd);
exit(0);
}
return fopen(name, "w");
}
int main()
{
FILE *log = LaunchLogWindow();
for(;;)
{
fprintf(log, "Hello world!\n");
}
}
A few bits are missing. Nothing cleans up the FIFO. I don't check for errors. It uses a C FILE object instead of a C++ ofstream. But you get the point.