ofstream never creates directories. In fact, C++ doesn't provide a standard way to create a directory.
Your could use dirname and mkdir on Posix systems, or the Windows equivalents, or Boost.Filesystem. Basically, you should add some code just before the call to ofstream, to ensure that the directory exists by creating it if necessary.