I cannot find any function in the Boost.Filesystem library to get a temporary filename. There has been some discussion about this functionality on the lists many years ago - did anything come of this? I need a cross-platform way to do this and was hoping boost would provide it :)
I was looking for exactly such a thing just yesterday and was surprised to find that boost::filesystem didn't have one. Here's the function I wrote instead (Windows only) in case it's of any use:
wpath TempFilePath() { vector
buffer(MAX_PATH); DWORD len = ::GetTempPath(buffer.size(), &buffer[0]); wstring directory(&buffer[0], buffer.size());
if (!GetTempFileName(directory.c_str(), NULL, 0, &buffer[0])) throw boost::system::system_error( ::GetLastError(), boost::system::system_category);
wstring file(&buffer[0], buffer.size());
return wpath(directory) / file; }
Thanks Alex. I have a similar function for Win32 as this is my primary platform. How should this be implemented for Linux with the same semantics and guarantees? Regards -- Craig