我用过'阅读'但是,当我调用时读取流
read_input('myFile.txt', N, K, B, Steps, Broken)
我的口译员回答错误。
这是我的代码:
read_input('myFile.txt', N, K, B, Steps, Broken) :-
open('myFile.txt', read, Stream),
read_line(Stream, [N, K, B]),
read_line(Stream, Steps),
read_line(Stream, Broken).
/*
* An auxiliary predicate that reads a line and returns the list of
* integers that the line contains.
*/
read_line(Stream, List) :-
read_line_to_codes(Stream, Line),
( Line = [] -> List = []
; atom_codes(A, Line),
atomic_list_concat(As, ' ', A),
maplist(atom_number, As, List)
).