Reputation: 2991
I liked to read the whole content of a text file using Nim.
I tried
let fileContent: string = readAll("file.txt")
but this doesn't compile.
Upvotes: 3
Views: 875
Reputation: 7661
The readAll proc requires as parameter a File
, which is what open returns. However, for a one liner you could use readFile:
let fileContent = readFile("file.txt")
Upvotes: 7
Reputation: 2991
It is most easily done so:
let filepath: string = "file.txt"
let f = open(filepath, fmRead)
let fileContent: string = readAll(f)
f.close()
(nothing has to get imported to do that)
Upvotes: 2