Table of Contents

C - C++ Files - Get path to temp directory

temp_directory.hpp

#pragma once
 
#include <string>
 
std::string get_temp_directory();

temp_directory.cpp

#include "temp_directory.hpp"
#include <filesystem>
 
#if __cplusplus > 201402L
  namespace fs = std::filesystem;
#else
  namespace fs = std::experimental::filesystem;
#endif
 
 
std::string get_temp_directory()
{
  return fs::temp_directory_path().string();
}

References

https://en.cppreference.com/w/cpp/filesystem/temp_directory_path