Reputation: 3
I want to write a function that reads a text file line by line. ie, read the first line until EOL and then treat this as a string, and repeat this until the text ends. I have managed only this much till now:
fun read file =
let val is = TextIO.openIn file
in
end
Upvotes: 0
Views: 677
Reputation: 1732
You can use TextIO.inputLine : instream -> string option
for this. Using ref
s you can do something like
let
val stream = TextIO.openIn file
val done = ref false
in
while not (!done) do
case TextIO.inputLine stream of
SOME s => print s
| NONE => done := true
end
You can also use the functions in TextIO.StreamIO
.
Upvotes: 1