Ada Text_IO Get后打印出来

时间:2014-11-05 14:58:10

标签: ada

我正在尝试以这种格式从用户那里获得字符输入:

Player 1: a

这是我的代码:

Ada.Text_IO.Put("Player"&Integer'Image(board.turn)&": ");
Ada.Text_IO.Get(Item => move);

现在,当我运行我的程序时,会发生这种情况:

a
Player 1: 

由于一些奇怪的原因,GET出现在PUT之前......我尝试翻转它们的位置,它仍然以相同的方式出现。

我最近将我的AdaCore GNAT从2012年升级到2014年,我在2012年没有遇到这个问题......

我错过了什么吗?

请帮忙!

如果您需要,可以使用/使用这些:

with Ada.Text_IO, Ada.Characters.Handling;
with Ada.Exceptions; use Ada.Exceptions;
USE Ada, Ada.Text_Io;

这是更多代码......不要担心人工智能......

完整代码:

PROCEDURE Main IS
  PACKAGE board is new connectfour;
  USE board;
begin
  PUT("   ********** CONNECT-FOUR *********"); Put_Line("");
  AI.start;
  while (not board.isFull) loop
    if AIwin = true then goto Win; end if;
    Put_Line(""); DELAY 0.5;
    Put("Player"&Integer'Image(board.turn)&": ");
    Get(move);
    if move='0' then goto Quit; end if;
    Put_Line("");
    if board.Move(move) = true then goto Win; end if;
    board.print; DELAY 0.5;
    AI.print;
  end loop;
  <<Win>>
  Put_Line("");
  Put_Line("PLAYER"&Integer'Image(board.turn)&" IS THE WINNER!");

  <<Quit>>
  AI.stop;
  Put_Line("");
  if move='0' then
    Put_Line("PLAYER"&Integer'Image(board.turn)&" HAS FORFEIT!");
    if board.turn = 1 then
      Put_Line("PLAYER 2 IS THE WINNER!");
    else
      Put_Line("PLAYER 1 IS THE WINNER BY DEFAULT!");
    end if;
  end if;
end Main;

1 个答案:

答案 0 :(得分:3)

标准输出可能正在缓冲。尝试

Ada.Text_IO.Put("Player"&Integer'Image(board.turn)&": “);
Ada.Text_IO.Flush;
Ada.Text_IO.Get(Item => move);

(后)

嗯,那不是答案。我刚试过

with Ada.Text_IO;
procedure Borovez is
   Move : Character;
begin
   Ada.Text_IO.Put ("Player" & Integer'Image (42) & ": ");
   --  Ada.Text_IO.Flush;
   Ada.Text_IO.Get (Item => Move);
end Borovez;

在GNAT GPL 2014 / Windows 7上,它完全符合预期。

您需要修改问题以包含Minimal, Complete, and Verifiable example