This language bar is your friend. Select your favorite languages!

Idiom #138 Create temp file

Create a new temporary file on filesystem.

#include <stdlib.h>
char tmpl[] = "XXXXXX.tmp";
int fd = mkstemp(tmpl);
using System.IO;
string file = Path.GetTempFileName();
import std.stdio;
auto f = File.tmpfile();
open (newunit=u,status="scratch")
import "io/ioutil"
tmpfile, err := ioutil.TempFile("", "")
import System.IO.Temp
withTempFile $ \f -> do
  -- do something with f
$f = tmpfile();
  H: THandle;
  H := FileCreate(GetTempFileName);
use Path::Tiny qw(tempfile);
my $path = tempfile;
import tempfile
file = tempfile.TemporaryFile()
require 'tempfile'
file ='foo') 
use tempdir::TempDir;
use std::fs::File;
let temp_dir = TempDir::new("prefix")?;
let temp_file = File::open(temp_dir.path().join("file_name"))?;

Do you know the best way to do this in your language ?
New implementation...

Idiom created by

Related idioms