fortran 菜鸟请教关于backspace的问题
slowlylhh
slowlylhh Lv.2
2009年12月12日 01:25:39
来自于水利软件
只看楼主

program mainimplicit nonecharacter*256 :: str_one_recordcharacter*256 :: str_one_record1open(100,file='data.txt')read(100,'(A5)',advance='no') str_one_recordbackspace(100)read(100,'(A5)',advance='no'

program main
implicit none
character*256 :: str_one_record
character*256 :: str_one_record1
open(100,file='data.txt')

read(100,'(A5)',advance='no') str_one_record
backspace(100)
read(100,'(A5)', advance='no') str_one_record1
write(*,*)str_one_record
write(*,*)str_one_record1
close(100)
end

运行结果:
forrtl: severe (268): end of record during read, unit 100, file C:\Program Files
\Microsoft Visual Studio\MyProjects\pro3\data.txt
Image PC Routine Line Source
pro3.exe 0040B0F9 Unknown Unknown Unknown
pro3.exe 0040AF57 Unknown Unknown Unknown
pro3.exe 0040A134 Unknown Unknown Unknown
pro3.exe 0040A569 Unknown Unknown Unknown
pro3.exe 00404E79 Unknown Unknown Unknown
pro3.exe 004040BF Unknown Unknown Unknown
pro3.exe 00401118 MAIN 13 aaa.f90
pro3.exe 004416B9 Unknown Unknown Unknown
pro3.exe 0042AAB9 Unknown Unknown Unknown
kernel32.dll 7C817067 Unknown Unknown Unknown
Press any key to continue
问题1:为什么会出现错误呢?只把上面程序中的红色advance=no去掉后
变成以下程序,运行就没有错误了,

program main
implicit none
character*256 :: str_one_record
character*256 :: str_one_record1
open(100,file='data.txt')


read(100,'(A5)',advance='no') str_one_record
backspace(100)
read(100,'(A5)')str_one_record1
write(*,*)str_one_record
write(*,*)str_one_record1
close(100)
end
结果显示:

12 8







Press any key to continue
问题2:这里按理说应该显示
12 8


12 8



Press any key to continue
可是为什么只显示一行12 8呢?



data.txt
12 89 77 89 89 12 34 22 44 55 66 77
12 999 878 777
398 789 765 98 765
78 89
12 89 77
12 999 878 777
398 789 765 98 765
免费打赏

相关推荐

APP内打开