在Visual Fortran上,利用fortran中的read将字符串中的数据赋值给各个对应的变量,结果出现NAN,而且还是中间的数据出现NAN
string_line = '## 2145 172800.00000000 900.00000000 59261 0.000000000 ‘
read (string_line, '(3x,i4,17x,f14.8,1x,i5,1x,f15.13)') a, b, c, d
循环的时候,结果有时正常,有时却提示b为NAN
你好同学,你可以在读入文件的时候定义一个符号变量xx
读入##
,然后一个b0
读入172800.00000000
program main
implicit none
integer:: a,c
real:: b0,b,d
character(len=100):: xx,string_line
string_line = '## 2145 172800.00000000 900.00000000 59261 0.000000000'
read(string_line, '(A2,1x,I4,1x,f15.8,1x,f12.8,1x,I5,1x,f11.9)')xx, a, b0, b, c, d
write(*,*)a,b,c,d
end
最后可见都读入成功了:
2145 900.000000 59261 0.00000000
有帮助还望给个宝贵的采纳支持一下答主答题呢