How to break to new line in Fortran when printing?

后端 未结 2 1492
名媛妹妹
名媛妹妹 2021-01-14 15:56

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?

for example

print*,\'This i         


        
2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-14 16:37

    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
    

    And, yet another way

    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
    

提交回复
热议问题