如何阻止控制台窗口立即关闭GNAT-GPS [英] How to stop console window from closing immediately | GNAT - GPS
问题描述
我有Ada程序,可以使用GNAT-GPS完美运行和编译。当我运行其exe文件并提供用户输入时,而不是说按任意键继续,该exe将立即关闭。
I have Ada program that runs and compile perfectly using GNAT - GPS. When I run its exe file and provide user input then instead of saying "Press any key to continue", the exe closes immediately.
我已经在网上大量搜索它,但是我只使用system('pause')找到了与c / c ++ / visual studio控制台窗口有关的信息;或Console.Readline()。
I have searched for it online alot but i only found info related to c/c++/visual studio console window using system('pause'); OR Console.Readline().
在Ada lanaguage中是否可以解决此问题?
Is there any way around for this in Ada lanaguage?
推荐答案
除了使用 Get_Line
或 Get
外,还可以使用
Ada.Text_IO
包。区别在于 Get_Line
和 Get
将继续读取用户输入,直到< Enter>
已被命中,而 Get_Immediate
仅在将标准输入连接到交互式设备(例如键盘)时按下单个键之前才会阻塞
Apart from using Get_Line
or Get
, you can also use Get_Immediate
from the Ada.Text_IO
package. The difference is that Get_Line
and Get
will continue to read user input until <Enter>
has been hit, while Get_Immediate
will block only until a single key has been pressed when standard input is connected to an interactive device (e.g. a keyboard).
这里是一个例子:
with Ada.Text_IO; use Ada.Text_IO;
procedure Main is
begin
-- Do some interesting stuff here...
declare
User_Response : Character;
begin
Put_Line ("Press any key to continue...");
Get_Immediate (User_Response);
end;
end Main;
注释
-
您应该在交互式终端(Bash,PowerShell等)中运行该程序,以实际看到
Get_Immediate
的效果。当您从GPS内运行程序时,仍然必须按Enter键才能实际退出程序。
You should run the program in an interactive terminal (Bash, PowerShell, etc.) to actually see the effect of
Get_Immediate
. When you run the program from within GPS, then you still have to press enter to actually exit the program.
这可能太多了,但是我认为表示 Get
仍然等待按下< Enter>
,因为它使用的是 fgetc 隐藏在C标准库(libc)中的code>(请参见此处和此处)。函数
fgetc
从C流中读取。 C流最初是为交互设备的行缓冲(源)。
This might be too much detail, but I think that Get
still waits for <Enter>
to be pressed because it uses fgetc
from the C standard library (libc) under the hood (see here and here). The function fgetc
reads from a C stream. C streams are initially line-buffered for interactive devices (source).
这篇关于如何阻止控制台窗口立即关闭GNAT-GPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!