"Print" a string (using stringstreams, for instance), and then use string.c_str() in the ofstream constructor.

There's also tmpnam in ... cstdio, I guess.