【问题标题】:Swi Prolog Read Write with FilesSwi Prolog 读写文件
【发布时间】:2015-08-17 03:09:31
【问题描述】:

所以我一直在尝试制作这个加密谓词,并且我让它适用于来自键盘和标准输出的输入,但我无法让它适用于文件,所以我需要帮助修复它。 我需要对 MessageFile 中的文本应用加密并将其写入 OutFile。

encrypt(MessageFile,Key,OutFile):- read(X),q(X,Key,R),!,string_to_list(S,R),
write(S).

正如我所说,它适用于标准输入\输出:

9 ?- encrypt(X,a,Y). 
|   abcdef.             
 bcdefg          
 true.

如果相关,我的 .pl 文件以及 in.txt 和 out.txt 位于 D:\Folder

【问题讨论】:

    标签: file encryption prolog swi-prolog


    【解决方案1】:

    您可以使用以下命令打开文件:

    open(MessageFile, read, Read),
    

    然后您可以使用read/2 从文件流中读取 Prolog 术语:

    read(Read, Term),
    

    PS:请注意,string_to_list/2 已弃用,string_codes/2 是其最新版本。

    【讨论】:

      猜你喜欢
      • 2014-05-09
      • 2011-06-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多