gpt4 book ai didi

fortran - 打印时如何在 Fortran 中换行?

转载 作者:行者123 更新时间:2023-12-03 19:44:10 25 4
gpt4 key购买 nike

这是非常简单的查询,但我无法找到确切的解决方案。
在 Fortran 中打印时如何换行?

例如

print*,'This is first line'
print*,'This is second line'

我想要以下输出
This is first line

This is Second line

即在两行之间添加空格。

在 Java 中我们使用 \n,在 html 中使用 <br> 可以完成这项工作..但是如何在 Fortran 中实现相同的目标?

最佳答案

有几种方法可以打印两行输出。

program foo
print *, 'This is the first line'
print *, 'This is the second line'
end program
是实现您想要的一种方式。另一个是做
program foo
write(*,'(A,/,A)') 'This is the first line', 'This is the second line'
end program foo
而且,还有一种方式
program foo
write(*,'(A)') 'A' // achar(13) // achar(10) // 'B'
end program foo
对于某些编译器,您可以使用选项
program foo
write(*,'(A)') 'A\r\nB'
end program foo
使用以下选项编译会产生:
$ gfortran -o z -fbackslash a.f90 && ./z
A
B

关于fortran - 打印时如何在 Fortran 中换行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58143647/

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