在默认情况下Put_Line(Turkey,“This is a test of turkey”);指的是向已经声明好了的文件对象输出内容,一般情况下,默认的输出指的是控制台上的输出,但是如果想要将默认的输出修改为对文件的输出,那么只需要 Set_Output(<文件对象>);,于是,在这句话下面出现的所有的put等输出语句的目标就都是文件TEST.txt,要关闭这一设置,只需要在要关闭的位置加上,
Set_Output(Standard_Output); – Return to the Standard default
即可。
with Ada.Text_IO,Ada.Integer_Text_IO;
use Ada.Text_IO,Ada.Integer_Text_IO;
procedure EasyOut is
Turkey:File_Type;-- declare an object of a class of file handling
begin
-- first we create the file
Create(Turkey,Out_File,"C:\Users\dosdiosas\Desktop\TEST.TXT");
Put_Line(Turkey,"This is a test of turkey");
Put(Turkey,"and it should work well ");
New_Line(Turkey,2);
Put_Line("half of the turkey test");
Set_Output(Turkey); -- Make Turkey the default output
Put_Line("This is another test of turkey");
Put("and it should work well.");
New_Line(2);
Put_Line(Standard_Output, "Half of the turkey test");
Set_Output(Standard_Output); -- Return to the Standard default
Put_Line("Back to the standard default output!");
Close(Turkey); -- close the file handler
end EasyOut;