文件读取问题
水平比较渣,又好久没用过了,编程时候读取文件有些问题,如果是这样一个文件我想要读取并且显示出来,跟我后面要处理的数据结构差不多这样总是出错program main
implicit none
real,dimension(3)::a,b,c
integer::l
open(2,file='a.dat')
do l=1,3
read(*,2)a(l),b(l),c(l)
enddo
do l=1,3
print*a(l),b(l),c(l)
enddo
close(2)
end用的codeblocks
报错如下
Error: FORMAT label 2 at (1) not defined
Process terminated with status 1 (0 minute(s), 0 second(s))
2 error(s), 0 warning(s) (0 minute(s), 0 second(s))
kaola132 发表于 2015-1-28 09:31
报错如下
Error: FORMAT label 2 at (1) not defined
Process terminated with status 1 (0 minute(s), 0 s ...
- read(*,2)a(l),b(l),c(l)
+ read(2,*)a(i),b(i),c(i) pasuka 发表于 2015-1-28 09:38
- read(*,2)a(l),b(l),c(l)
+ read(2,*)a(i),b(i),c(i)
谢谢,不过又出现了这个报错,昨天也是,
Error: Expected comma in I/O list at (1)
Process terminated with status 1 (0 minute(s), 0 second(s))
1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) read(2,*)a(l),b(l),c(l)
print*, a(l),b(l),c(l) Program Main
Implicit None
Real, Dimension (3) :: A, B, C
Integer :: L
Open (2, File='a.dat')
Do L = 1, 3
Read (2, *) A(L), B(L), C(L) !// 2 和 *写反了
End Do
Do L = 1, 3
Print *, A(L), B(L), C(L) !// 少个逗号
End Do
Close (2)
End Program Main
页:
[1]