C++: Where does the ofstream class save the files to?

The stream classes, like all other file-opening functions, use the current directory when you provide a relative path. You can control the current directory with a function like chdir, but a better solution is to use fully qualified file names. Then you remove your program’s dependency on the current directory.

Leave a Comment