*在Fortran输入/输出中的用途是什么

编程入门 行业动态 更新时间:2024-10-26 04:28:15
本文介绍了*在Fortran输入/输出中的用途是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在学习Fortran,因为我认为我会学习它。然而,我完全没有发现打印,阅读等目的*的信息:

程序main print *,你好,世界! end program main

这个 * ?我已经做了一些研究,但我认为我没有正确理解,我不想继续学习,直到我真正知道 * 的要点。

从我设法找到的我认为它是某种格式说明符,然而,我不明白这意味着什么,我不知道我是否甚至正确。我找到的所有教程都告诉我要写什么来打印到控制台,但不是 * 实际上意味着什么。

解决方案

您正确的是它是一个格式说明符。

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 main

What 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)') A

which 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)', A

to 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输入/输出中的用途是什么

本文发布于:2023-10-29 13:05:39,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:用途   Fortran

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!