Ada Programming/Libraries/Ada.Text IO
The package Text_IO
Used for simple Input Output (IO) in text format.
Tips and Tricks for Text_IO
Read a whole line from the console with Ada 95
Get_Line () procedure gets a line of text up until the receiving string fills up. If the line is longer than the buffer then you need to read it more than once. The following example from Mathematical calculations shows how this is done:
with Ada.Text_IO; with Ada.Strings.Unbounded; procedure Numeric_4 is package Str renames Ada.Strings.Unbounded; package T_IO renames Ada.Text_IO; ... function Get_Line return Str.Unbounded_String is BufferSize : constant := 2000; Retval : Str.Unbounded_String := Str.Null_Unbounded_String; Item : String (1 .. BufferSize); Last : Natural; begin Get_Whole_Line : loop T_IO.Get_Line (Item => Item, Last => Last); Str.Append (Source => Retval, New_Item => Item (1 .. Last)); exit Get_Whole_Line when Last < Item'Last; end loop Get_Whole_Line; return Retval; end Get_Line; ...
Ada 2005 has a function Get_Line which returns a newly created string which contains the whole string.
Reading a whole line from a file with Ada 95
In principle it is the same as in console reading but you have to check for the end of file as well:
- Ada Programming
- Ada Programming/Input Output
- Ada Programming/Libraries
- Ada Programming/Libraries/Ada
- Ada Programming/Libraries/Ada.Strings.Unbounded.Text_IO