打印时如何在Fortran中换行? [英] How to break to new line in Fortran when printing?

查看:1421
本文介绍了打印时如何在Fortran中换行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

It is very simple query but I'm not able to find the exact solution. How to break to new line when printing in Fortran?

例如

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

我要关注输出

This is first line

This is Second line

即在两行之间添加空格.

That is add space between two lines.

在Java中,我们使用\n;在html中,我们使用<br>.

In java we use \n and in html using <br> does the job..but how to achieve same in Fortran?

推荐答案

有两种打印两行输出的方法.

There are several ways to print two lines of output.

program foo
   print *, 'This is the first line'
   print *, 'This is the second line'
end program

是实现所需目标的一种方法.另一个是要做

is one way to achieve what you want. Another is to do

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

对于某些编译器,您可以使用选项

And with some compilers you can use options

program foo
   write(*,'(A)') 'A\r\nB'
end program foo

使用以下选项进行编译会产生:

Compiling with the following options yields:

$ gfortran -o z -fbackslash a.f90 && ./z
  A
  B

这篇关于打印时如何在Fortran中换行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆