-- Chapter 24 - Program 4 with Ada.Text_IO, Ada.Integer_Text_IO, Ada.Streams.Stream_IO; use Ada.Text_IO, Ada.Integer_Text_IO, Ada.Streams.Stream_IO; procedure Stream is My_File : Ada.Streams.Stream_IO.FILE_TYPE; My_File_Access : Ada.Streams.Stream_IO.STREAM_ACCESS; type RESULT is (WIN, LOSE, TIE, FORFEIT); type BOX is record Length : INTEGER; Width : INTEGER; Height : INTEGER; end record; Big_Box, Small_Box : BOX := (7, 8, 9); Football, Baseball : RESULT := TIE; Dogs, Pigs, Cats : INTEGER := 27; Animal : INTEGER := 100; begin -- Create a stream to a file in the output mode to write to. Ada.Streams.Stream_IO.Create(My_File, Out_File, "funny.txt"); My_File_Access := Ada.Streams.Stream_IO.Stream(My_File); INTEGER'Write(My_File_Access, Dogs); BOX'Write(My_File_Access, Big_Box); BOX'Write(My_File_Access, Small_Box); RESULT'Write(My_File_Access, Baseball); INTEGER'Write(My_File_Access, Pigs); RESULT'Write(My_File_Access, Football); INTEGER'Write(My_File_Access, Cats); Ada.Streams.Stream_IO.Close(My_File); -- Open the stream in the input mode to read from it. Open(My_File, In_File, "funny.txt"); My_File_Access := Stream(My_File); INTEGER'Read(My_File_Access, Animal); BOX'Read(My_File_Access, Small_Box); -- The others can be read here too Put("Animal has a value of "); Put(Animal, 6); New_Line; Close(My_File); end Stream; -- Result of execution -- Animal has a value of 27