4
我正在尝试读取文件并将从文件中读取的元素作为输入返回给另一个函数。从文件返回值 - ocaml
当我从文件中读取数据时,如何返回值? 我尝试了我所知道的一切,但仍然无法挽回。
我的代码如下:
let file = "code.txt";;
let oc = open_out file in (* create or truncate file, return channel *)
fprintf oc "%s\n" (play); (* write code to file returned from calling (play) function *)
close_out oc ;;
(*read from file*)
let read l=
let f x =
let ic = open_in file in
let line = input_line ic in (* read line from in_channel and discard \n *)
print_endline line; (* write the result to stdout *)
((x^line) :: l);
flush stdout;
close_in ic ;
in
f l
;;
prompt: read;; function call outputs:
- : unit =()
我的文件包含一个字符串,它是需要的,作为另一个功能输入一个代码。
请帮忙。我不知道我哪里出错了。
谢谢。
非常感谢你!我完全失去了!谢谢 :) – JJunior 2010-11-29 20:15:11