Fortran输入/输出中*的目的是什么 [英] What is the purpose of * in Fortran input/output

查看:27
本文介绍了Fortran输入/输出中*的目的是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习 Fortran,因为嗯,是的,我认为我会学习它.但是,我完全没有发现 * 的用途在打印、阅读等方面的信息:

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.

在 Wikibooks 上有一个页面与 IO 相关,并指出:

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

当谈到 read 语句时.这也适用于 writeprint 语句.

when talking about the read statement. This applies to the write and print statements too.

对于定点实数:Fw.d;w 是分配给数字的空格总数,d 是小数位数.

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.

他们给出的例子是

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

得到四舍五入的输出.

在您的示例中,您只是打印文本,因此无需进行特殊格式设置.此外,如果您将格式说明符保留为 * 它会将默认格式应用于实数等.

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输入/输出中*的目的是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆