在Fortran中,write语句中不能直接赋值,例如下面两种错误案例:
write(*,*) "dis=" dis = sqrt(A**2 + B**2 + C**2) 这里两处错误
“Syntax error, found CHARACTER_CONSTANT 'dis=' when expecting one of: => = . [ % (”
“This name must be the name of a variable with a derived type (structure type).”
write(*,*) "dis=", dis = sqrt(A**2 + B**2 + C**2) 这里一处错误
“Syntax error, found CHARACTER_CONSTANT 'dis=' when expecting one of: => = . [ % (”
可以修改为:
write(*,*) "dis=", sqrt(A**2 + B**2 + C**2)
报错原因:
"dis=" 和 sqrt 中间的逗号不可以省略;write语句中不能直接赋值。