再会。编写程序并运行它。该程序本身没有给出任何错误,它似乎可以工作。创建文件但不向文件写入任何内容。两个程序的行为已经相同。这是一个
program ioposneg
implicit none
integer::i,a,x
do i=1,10
open(10,file='posneg')
read(10,*) a
if (a>0) then
open(15,file='pos')
x=a
write(15,*) x
else
open(20,file='neg')
x=a
write(20,*) x
end if
end do
print*,'finished'
end program ioposneg
这是第二个
program ioformat
implicit none
real::x=0,ex
integer::i
character(len=5)::c='x',ec='ex'
open(10,file='xex')
write(10,2) c,ec
2 format(2a10)
do i=1,11
ex=x**2
open(10,file='xex')
write(10,5)x,ex
5 format(2f10.5)
x=x+0.1
end do
print*,'finished'
end program ioformat
第一个程序的可读文件如下所示:
2
3
-9
15
-25
-47
85
68
-10
-5
原来需要在循环外打开文件。一旦我以这种方式打开文件进行循环,它就起作用了:
与第二个程序相同