std::tmpfile() not picking TMPDIR location
问题 I am using std::tmpfile() to create temporary files, but I want to use the location other than /tmp. I am exporting $TMPDIR to point to the new location, but std::tmpfile() doesn't pick the new location. How to create temporary files with std::tmpfile() in a folder other than /tmp? 回答1: A quick test program #include <stdio.h> #include <stdlib.h> #include <cstdlib> #include <iostream> int main() { const char* tf = std::tmpnam(nullptr); std::cout << "tmpfile: " << tf << '\n'; return 0; } and an