在几年前对Fortran90做了简要介绍之后,我正在学习Fortran77。在Fortran中打印整数时,必须指定要为打印整数保留多少空格。考虑一下这个计划..。
implicit none
integer :: i
i = 123
write(*, '(A, I3, A)') "'", i, "'" !3 spaces for output = no padding
write(*, '(A, I5, A)') "'", i, "'" !5 is too many, so output is padded
write(*, '(A, I2, A)') "'", i, "'" !2 is too few, so output is jibberish
write(*, '(A, I:, A)') "'", i, "'" !Default behavior
end program...which生成以下输出。
'123'
' 123'
'**'
' 123'当我不知道整数中有多少位数时,如何分配整数打印的正确空间?
Update:如果您的编译器与F95兼容,您可以使用I0编辑描述符(例如,在上面的示例中,将'(A, I0, A)'用于write函数的第二个参数)。谢谢你!
发布于 2011-01-21 17:54:20
使用I0编辑描述符。如果你对F90严格要求,那么我想这是行不通的。
https://stackoverflow.com/questions/4760600
复制相似问题