In boost filesystem there is a function create_directory
which creates a directory. How do I create a file? I could create one by defining a boost::filesystem::ofstream
object but that would also open the file, so I would have to call close
on it before I could do other stuff to it, like renaming or deleting. Is this the only way?
To create a file, use either the ofstream or fstream class, and specify the name of the file. To write to the file, use the insertion operator ( << ).
Unlike a large portion of the Boost ecosystem, boost::filesystem is not header-only. However, integration into a project was quite simple, and the functionality it provided was impressive.
The Boost Filesystem Library provides portable facilities to query and manipulate paths, files, and directories. The motivation for the library is the need to be able to perform portable script-like operations from within C++ programs.
Boost Filesystem V3 doesn't provide a touch(1)
function;
Even touch
will creat+close a file, just look at the output of strace
:
open("/tmp/q", O_WRONLY|O_CREAT|O_NOCTTY|O_NONBLOCK, 0666) = 47
dup2(47, 0) = 0
close(47) = 0
utimensat(0, NULL, NULL, 0) = 0
I think your most reasonable bet is to just create a wrapper function that closes the file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With