How to read the data from text file in Prolog
How do I read data from a text file in Prolog? Is there any example of file reading in SWI-pro开发者_如何转开发log?
readfacts:-
open('example.txt',read,In),
repeat,
read_line_to_codes(In,X),writef(" "),
writef(X),nl,
X=end_of_file,!,
nl,
close(In).
Prolog has a number of input/output predicates, falling into two categories: the new ISO ones or the old ones compatible with Edinburgh and DEC 10 versions. For full details including example code, see the reference manual following above links.
精彩评论