简体   繁体   English

使用在线 Fortran 编译器从标准输入读取时出现“文件结束”

[英]"End of file" when reading from standard input with an online Fortran compiler

I am running the following code via an online Fortran compiler .我正在通过在线 Fortran 编译器运行以下代码。

PROGRAM ONE 

IMPLICIT NONE 

REAL:: v

READ (*,*) v


IF ( sqrt(v) > 1. ) THEN
WRITE(*,*) 'At first: sqrt(v) > 1.'

ELSE IF ( sqrt(v) < 1. ) THEN 

WRITE(*,*) 'At first: sqrt(v) < 1. '
ELSE
WRITE(*,*) 'At first: sqrt(v) == 1.'
END IF 

END PROGRAM ONE 

I get the following message.我收到以下消息。

$gfortran -std=gnu *.f95 -o main
$main
At line 7 of file main.f95 (unit = 5, file = 'stdin')
Fortran runtime error: End of file

Error termination. Backtrace:
#0  0x7fb0b576beda
#1  0x7fb0b576ca85
#2  0x7fb0b576d24d
#3  0x7fb0b58e3513
#4  0x7fb0b58dc459
#5  0x7fb0b58ddbb9
#6  0x400824
#7  0x4009bd
#8  0x7fb0b4c334d9
#9  0x400719
#10  0xffffffffffffffff

When you have a read statement like当你有一个像这样的读语句

READ (*,*) v

you may typically expect the program to pause, waiting for data from standard input .您通常可能希望程序暂停,等待来自标准输入的数据。 However, it's possible that a normal file has been redirected to standard input, in which case the program tries to read from that file.但是,普通文件可能已被重定向到标准输入,在这种情况下,程序会尝试从该文件中读取。 If that file is empty, then an end-of-file condition (see your runtime error message) will occur, rather than the program waiting.如果该文件为空,则会出现文件结束条件(请参阅您的运行时错误消息),而不是程序在等待。

In your case, with your online compiler, there is a tab next to the source code where you can enter the data which will be used as standard input.在您的情况下,使用您的在线编译器,源代码旁边有一个选项卡,您可以在其中输入将用作标准输入的数据。 Unless you put the input here, you will see this failure.除非你把输入放在这里,否则你会看到这个失败。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM