I'm looking for a way to write two int
s to a file. There will be many pairs of two int
s. Between the two numbers there should be a space (I mean ''). For example, something like this:
1 2
6 896
243 865
....
You can use something like this:
let rec print_numbers oc = function
| [] -> ()
| e::tl -> Printf.fprintf oc "%d %d\n" (fst e) (snd e); print_numbers oc tl
let () =
let nums = [(1, 2); (6, 896); (243, 865)] in
let oc = open_out "filename.txt" in
print_numbers oc nums;
close_out oc;
This assumes your data is a list of pairs.
If you use Core
, you can do this:
open Core.Std
let () = Out_channel.write_all "your_file.txt" ~data:"Your text"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With