我正在阅读http://en.wikibooks.org/wiki/Fortran/Fortran_simple_input_and_output 上的 Fortran 教程。在下面的程序中,unit=out_unit 做什么?
program xproduct
implicit none
integer :: i,j
integer, parameter :: out_unit=20
print*,"enter two integers"
read (*,*) i,j
open (unit=out_unit,file="results.txt",action="write",status="replace")
write (out_unit,*) "The product of",i," and",j
write (out_unit,*) "is",i*j
close (out_unit)
end program xproduct
Run Code Online (Sandbox Code Playgroud)
当我运行这个程序时,文本文件 results.txt 包含以下文本:
The product of 2 and 3
is 6
Run Code Online (Sandbox Code Playgroud)
它指定要写入的“终端”。out_unit 中包含的数字代表您用open
语句打开的文件。如果您没有使用该open
语句并指定文件,则输出将是fort.20
某些端子编号具有特定含义。例如,6 是(通常)标准输出,5 是(通常)标准输入。
归档时间: |
|
查看次数: |
2354 次 |
最近记录: |