0
平台若干发呆:Linux的2.6.18 x86_64的约帕斯卡输出
编译器:Free Pascal编译版本2.2.2 [2008年11月5日]为x86_64的
的源代码是:
Program main;
var invalue:string;
Begin
(*Until the EOF, this loop continue to work*)
while not eof do
begin
Write('Please input the express: ');
Flush(StdOut);
Readln(invalue);
Writeln('The expression is: ',invalue);
end;
Writeln('');
Writeln('Exit the program. Bye!');
End.
我编译并运行它。但输出是这样的:
123
Please input the express: The expression is: 123
234
Please input the express: The expression is: 234
345
Please input the express: The expression is: 345
Exit the program. Bye!
这些数字是我的输入。我搜索了它,并认为这是因为缓冲区。所以我试图在写入之后添加flush(stdout)或flush(输出)。但它仍然不能很好地工作。
我希望它的工作原理为:
Please input the express: 123
The expression is: 123
Please input the express: 234
The expression is: 234
Please input the express: 345
The expression is: 345
Exit the program. Bye!
谢谢!很遗憾我的傻瓜〜
增加: 我试图为(谢谢你,Aloush!)
Program main;
var invalue:string;
Begin
(*Until the EOF, this loop continue to work*)
while not eof do
begin
Write('Please input the express: ');
Flush(StdOut);
Readln(invalue);
Writeln('')
Writeln('The expression is: ',invalue);
end;
Writeln('');
Writeln('Exit the program. Bye!');
End.
结果还是没有得到很好的为:
1
Please input the express:
The expression is: 1
2
Please input the express:
The expression is: 2
3
Please input the express:
The expression is: 3
4
Please input the express:
The expression is: 4
5
Please input the express:
The expression is: 5
Exit the program. Bye!
的Readln在第一次写入之前仍然执行。
顺便说一句,我也尝试:
Program main;
var invalue:string;
Begin
(*Until the EOF, this loop continue to work
while not eof do
begin*)
Repeat
Write('Please input the express: ');
Flush(StdOut);
Readln(invalue);
Writeln('The expression is: ',invalue);
Until eof;
Writeln('');
Writeln('Exit the program. Bye!');
End.
在这种情况下,第一个循环是好的,但其他人仍然是错误的。
Please input the express: 123
The expression is: 123
234
Please input the express: The expression is: 234
345
Please input the express: The expression is: 345
Exit the program. Bye!
谢谢!
最终解决方案: http://www.amath.unc.edu/sysadmin/DOC4.0/pascal/lang_ref/ref_io.doc.html#592 这是因为,在EOF实际上相当于一个隐含的读取。 当前的代码应该是:
Program main;
var invalue:string;
Begin
(*Until the EOF, this loop continue to work*)
Write('Please input the express: ');
while not Eof do
begin
Readln(invalue);
Writeln('The expression is: ',invalue);
Write('Please input the express: ');
end;
Writeln('');
Writeln('Exit the program. Bye!');
End.
最后,在这里谢谢你,Aloush和keiy上CSDN!
请在答案左侧的箭头滑动以将其标记为“已接受”。这比编辑标题“解决”要好。 – spraff