以下代码试图将文件读取到存储字符的存储块中,并从该块中读取数据,而不是从原始文件中读取数据。 (代码是根据here进行修改的)
program read_file
implicit none
integer :: n
character(len=:), allocatable :: s
character(len=5) :: a, b
open(unit=10, file="read_file.f", action="read",
1 form="unformatted", access="stream")
inquire(unit=10, size=n)
allocate(character(n) :: s)
read(10) s
close(10)
print "(A)", s
read ( s, * ) a
read ( s, * ) b
print *, a
print * , b ! meant to read from the previously visited place
end program read_file
当尝试从字符块“ s”中读取时,程序始终从其开头读取,而不是在读取文本文件时连续读取。因此,“ a”和“ b”完全相同。有没有办法像读取文件一样读取's'?谢谢!