首页 > 解决方案 > gfortran 从 txt 文件读取时产生错误

问题描述

我是 Fortran 的初学者,我正在尝试使用 Eclipse 在 Fortran 中编写一个简单的程序。这个想法是从 .txt 文件中读取两个整数,然后将它们的总和写入其他 .txt 文件并保存。这些代码已在 Eclipse 中成功编译并运行,但是当我运行其可执行文件时,会产生以下错误:

At line 6 of file ../Alo.f95 (unit = 11, file = 'SumData3.txt')
Fortran runtime error: End of file

Error termination. Backtrace:
#0  0x108c17579
#1  0x108c18235
#2  0x108c18999
#3  0x108ce001b
#4  0x108cdaa39
#5  0x108c10c73
#6  0x108c10e2a
logout
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.

这是我的代码

program test_random_number
implicit none
    integer :: x,y,z
    open(unit=11, file="SumData3.txt",status='old')
    read(11,*) x,y
    close(11)
    z = x+y
    open(unit=12, file="SumData4.txt")
    write(12,*) "Summation =", z
    close(12)
end

请你帮助我好吗?十分感谢。

标签: fortrangfortran

解决方案


推荐阅读