标签: ocaml
从空格分隔的stdin读取一堆整数的最简单方法是什么?在这种情况下,我知道有多少,虽然未知的情况对应于while(std :: cin>> n){a.push_back(n);在C ++中也很高兴知道。
答案 0 :(得分:3)
您可以尝试Scanf模块。请参阅其文档here。
Scanf
let get_ints queue = let aux () = Scanf.scanf "%d " (fun n -> Queue.push n queue); aux () in try aux () with _ -> ()
其他标准方式允许您这样做,您可能需要查看ocamllex,Str或Genlex。当然,在OCaml中还有其他lexing / parsing库,但对于哪一个是最好的,这将是一个很大的争论。