Nim: How to write a file

Mar 22, 2022

Writing a file is as straight-forward as reading one:

let text = "Hello World!"
writeFile("hello.txt", text)

Writing each line incrementally is also similar:

proc writeHello() =
  let lines = ["Hello", "World", "!!"]
  let f = open("hello.txt", fmWrite) # fmWrite is the file mode constant 
  defer: f.close()

  for line in lines:

Hi, I'm Glenn! 👋 I'm currently Director of Product (Terraform) @ HashiCorp, and we're hiring! If you'd like to come and work with me and help make Terraform Cloud even more amazing we have multiple positions opening in Product ManagementDesign, and Engineering & Engineering Management across a range of levels (i.e., junior through to senior). Please send in an application ASAP so we can get in touch.