use*_*510 7 io file-io ocaml file
我正在寻找一种方法来将两个ints 写入文件.会有很多对两个int.在两个数字之间应该有一个空格(我的意思是' ').例如,像这样:
1 2
6 896
243 865
....
Run Code Online (Sandbox Code Playgroud)
你可以使用这样的东西:
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;
Run Code Online (Sandbox Code Playgroud)
这假设您的数据是对的列表.
如果您使用Core,您可以这样做:
open Core.Std
let () = Out_channel.write_all "your_file.txt" ~data:"Your text"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4408 次 |
| 最近记录: |