38. Temporary log files

The logging class that you have to implement for this task should:

  • Have a constructor that creates a text file in a temporary directory and opens it for writing
  • During destruction, if the file still exists, close and delete it
  • Have a method that closes the file and moves it to a permanent path
  • Overloads operator<< to write a text message to the output file

In order to create unique names for the file, you could use a UUID (also known as GUID). The C++ standard does not support any functionality related to that, but there are third-party libraries, such as boost::uuid, CrossGuid, or stduuid, which is actually a library that I created. For this implementation, I will use the last one. You can find it at https://github.com/mariusbancila/stduuid ...

Get The Modern C++ Challenge now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.