这个 * ?我已经做了一些研究,但我认为我没有正确理解,我不想继续学习,直到我真正知道 * 的要点。
从我设法找到的我认为它是某种格式说明符,然而,我不明白这意味着什么,我不知道我是否甚至正确。我找到的所有教程都告诉我要写什么来打印到控制台,但不是 * 实际上意味着什么。
解决方案您正确的是它是一个格式说明符。
Wikibooks上有一个关于 IO 并表明:
第二个*指定用户希望在中使用读取的格式的格式>读取语句。这也适用于 write 和 print 语句。
对于固定点实数:Fw.d; w是分配给该数字的空间总数,d是小数位数。
他们给出的例子是
REAL :: A READ(*,'(F5.2)')A读取小数点前后两位数的实数。因此,如果您打印的是实际的号码,您可以使用:
PRINT'(F5.2)',A得到四舍五入的输出结果。
你只是打印文本,所以没有特殊的格式。另外,如果您将格式说明符保留为 * ,它会将默认格式应用于reals等。
I am learning Fortran because well, yeah, thought I'd learn it. However, I've found utterly no information on what the purpose of * is in print, read, etc:
program main print *, "Hello, world!" end program mainWhat is the purpose of this *? I've done some research however I don't think I understand it properly, I don't want to carry on learning until I actually know the point of *.
From what I've managed to find I think that it's some sort of format specifier, however, I don't understand what that means and I have no idea if I'm even correct. All the tutorials I've found just tell me what to write to print to the console but not what * actually means.
解决方案You are correct in that it is a format specifier.
There's a page on Wikibooks to do with IO and that states:
The second * specifies the format the user wants the number read with
when talking about the read statement. This applies to the write and print statements too.
For fixed point reals: Fw.d; w is the total number of spaces alloted for the number, and d is the number of decimal places.
And the example they give is
REAL :: A READ(*,'(F5.2)') Awhich reads a real number with 2 digits before and after the decimal point. So if you were printing a real number you'd use:
PRINT '(F5.2)', Ato get the rounded output.
In your example you're just printing text so there's no special formatting to do. Also if you leave the format specifier as * it will apply the default formatting to reals etc.
更多推荐
*在Fortran输入/输出中的用途是什么
发布评论