当我想编写一个代码,我想用它打开一个 txt 文件时,在其中写入一个实数并将该数字传递给我代码中的一个变量。
我的代码看起来像:
open (unit = 22, file = x_file, status = 'old')
write(22, *) 1.2345
do while (ios == 0)
read(22,*, iostat=ios) reader
end do
write(*,*) reader
编译后,变量“reader”得到了一个非常小的数字(2.2460454138806765E-314)。删除该行后
write(22, *) 1.2345
并直接在 txt 文件中小费数字我的变量“阅读器”变为 1.2345。那可能是什么原因?
将值写入文件后
write(22, *) 1.2345
该文件位于末尾。
当到达文件末尾时,您的声明
read(22,*, iostat=ios) reader
不读取任何内容,设置ios
为文件末尾的非零值 end 进一步进行。的值reader
未定义!
如果 iostat 非零,则不能使用输入列表中的变量值。
你想要:
open ( unit = 22, file = x_file, status = 'old' )
write(22, *) 1.2345
rewind(22)
read(22,*, iostat=ios) reader
if (ios/=0) stop
write(*,*) reader
?
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句