gpt4 book ai didi

file-io - 在 Fortran 中打开和编写语句

转载 作者:行者123 更新时间:2023-12-01 00:31:36 24 4
gpt4 key购买 nike

我正在学习 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

当我运行这个程序时,文本文件 results.txt 包含以下文本:

 The product of           2  and           3
is 6

最佳答案

它指定要写入的“终端”。 out_unit 中包含的数字代表您使用 open 语句打开的文件。如果您没有使用 open 语句并指定文件,则输出将是 fort.20

一些终端号码有特定的含义。例如,6(通常)是标准输出,5 是(通常)标准输入。

关于file-io - 在 Fortran 中打开和编写语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6471161/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com