[Fortran] 纯文本查看 复制代码
program ex33
implicit none
integer :: a, b, fileid, k, error
character (len=512):: str
character (len=512) :: filename="ex32.txt"
open (newunit=fileid, file=filename, form="formatted", access="direct", recl=512, status="old")
do while (.true.)
read (*,*) k
read (fileid, "(a512)", rec=k, iostat=error) str
if (error/=0) exit
read (str, *) a, b
write (*,*) a, b
end do
close (fileid)
end
[Fortran] 纯文本查看 复制代码
program ex33
implicit none
integer :: i , a, b, fileid, k, error
character (len=512):: str
character (len=512) :: filename="ex32.txt"
open (newunit=fileid, file=filename , status="old") !//采用有格式顺序读写
do
read (*,*) k
rewind(fileid)
do i = 1 , k - 1
read( fileid , * )
end do
read ( fileid, "(a512)", iostat=error ) str
if (error/=0) exit
read (str, *) a, b
write (*,*) a, b
end do
close (fileid)
end