【发布时间】:2016-04-21 19:59:01
【问题描述】:
我想从文件中读取一些数字,将它们放到一个列表中,最后将它们显示在屏幕上。
numbers.txt 目前有2 3 5 7 11 但是作为输出我得到11 7 5 3 2 - : unit = ()
为什么会这样?
let rec int_list_from_sb sb n =
match n with
| 0 -> [];
| _ -> (bscanf sb " %d" (fun a -> a))::(int_list_from_sb sb (n - 1));;
let file_name = open_in "numbers.txt" in
let sb = Scanning.from_channel file_name in
let int_list = int_list_from_sb sb 5 in
List.iter (fun a -> print_int a) int_list;;
【问题讨论】:
标签: ocaml