这是一个非常简单的查询,但我找不到确切的解决方案。在Fortran中打印时如何换行?
例如
print*,'This is first line'
print*,'This is second line'我想要以下输出
This is first line
This is Second line也就是说,在两行之间添加空格。
在java中我们使用\n,而在html中使用<br>,job..but在Fortran中如何实现呢?
发布于 2019-09-28 14:06:08
有几种方法可以打印两行输出。
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发布于 2019-09-28 15:53:24
有许多方法可以管理您想要的内容。我们可以打印空白记录,也可以显式添加换行符。
换行符由内部函数NEW_LINE返回
print '(2A)', 'First line', NEW_LINE('a')
print '(A)', 'Second line'NEW_LINE('a')可能会产生类似于ACHAR(10)或CHAR(10,KIND('a'))的效果。
空白记录可以通过没有输出项来打印:
print '(A)', 'First line'
print '(A)'
print '(A)', 'Second line'或者我们可以使用斜杠编辑
print '(A,/)', 'First line'
print '(A)', 'Second line'如果我们不使用多个print语句,我们甚至可以使用这些相同的想法来组合编写。例如:
print '(A,:/)', 'First line', 'Second line'
print '(*(A))', 'First line', NEW_LINE('a'), NEW_LINE('a'), 'Second line'NEW_LINE('a')也可以在格式化字符串中使用,但是除了斜杠编辑之外,这似乎不会增加太多价值。
https://stackoverflow.com/questions/58143647
复制相似问题