ocaml - print string buffer from file contents -
i want print contents of file. tried use string buffer:
let ch = open_in "myfile.txt" in let buf = buffer.create 1024 in (try buffer.add_channel buf ch max_int _ -> ()); close_in ch; let string = buffer.contents buf print_endline string this gives me syntax error.
how can this?
you need give right channel length:
let ic = open_in "foo" in let len = in_channel_length ic in let buf = buffer.create len in buffer.add_channel bif ic len; let str = buffer.contents b in print_endline str
Comments
Post a Comment