小编use*_*104的帖子

Prolog - 意外的文件结束

在Prolog错误中读取文件

嗨,我正在研究一个Prolog项目,我需要读取整个文件.我有一个名为'meno.txt'的文件,我需要阅读它.我在堆栈上找到了一些代码.代码如下:

main :-
  open('meno.txt', read, Str),
  read_file(Str,Lines),
  close(Str),
  write(Lines), nl.


read_file(Stream,[]) :-
    at_end_of_stream(Stream).


read_file(Stream,[X|L]) :-
    \+ at_end_of_stream(Stream),
    read(Stream,X),
    read_file(Stream,L).
Run Code Online (Sandbox Code Playgroud)

当我调用main/0谓词时,我收到一个错误,指出文件意外结束.我的文件看起来像这样:

line1
line2
line3
line4
Run Code Online (Sandbox Code Playgroud)

我在这里也发现了类似的问题以及ASCII和UTF编码的解决方案,但我尝试过,看起来它不是我的解决方案.有人可以帮忙吗?

io input prolog

2
推荐指数
2
解决办法
7968
查看次数

标签 统计

input ×1

io ×1

prolog ×1