# Ada Programming/Libraries/Ada.Text IO

This language feature is available from Ada 95 on.
Ada.Text_IO is a unit of the Predefined Language Environment since Ada 95.

## Description

The package Text_IO is used for simple Input Output (I/O) in text format.

## Tips and Tricks for Text_IO
### Read a whole line from the console

Ada 2005 has a function Get_Line which returns a newly created string containing the whole line:
With older Ada generations, you need a little work to get the complete line with one call. The Get_Line procedure gets a line of text of as many characters the Item can hold or up to the new_line indicator, whichever comes first. (The new_line indicator's representation is implementation defined.) It has the following specification:
To be specific, consider an Item that can hold as much as 80 characters. Let's take two lines to read, one holding less that 80 characters, say 10, the other at least 80, perhaps more. Calling
will read the first line up to the new_line indicator and consume them; Item's first 10 characters will be filled with the text read, the rest is junk; Last will hold the last filled index.
The next call will read the maximum Item can hold, i.e. 80 characters; the rest of the line (if any) and the new_line indicator remain unconsumed. Thus Last will be Item'First - 1 + 80. In order to consume the rest of the line, you have to call Get_Line again. The result will be like one of the two possibilities above, depending on the remaining line length. If no characters are read (i.e. when the new_line indicator is the only thing left unread), Last will hold value Item'First - 1.
The following example shows how the complete line could be read:
As an exercise, change the calls at (*) to
and see which values Item and Last will hold. Which criterium will you then need to exit the loop at (**)?
(This is of course not a very sensible idea to code like this, but as a learning instruction, it's fine.)

### Read a whole line from a file

In principle it is the same as in console reading but you have to check for the end of file as well:
End_of_File is always False for console input (except when you manage to enter the implementation defined end_of_file indicator). A well-formed text file (i.e. one created with Ada.Text_IO) will always hold an end_of_line (and an end_of_page) indicator before the end_of_file indicator (see procedure Close).

## Generic nested packages

Ada.Text_IO has the following nested packages for input/output of scalar types. The only parameter is the involved type.
* Decimal_IO
* Enumeration_IO
* Fixed_IO
* Float_IO
* Integer_IO
* Modular_IO

## See also
### Wikibook

* Ada Programming
* Ada Programming/Input Output
* Ada Programming/Libraries
* Ada Programming/Libraries/Ada
* Ada Programming/Libraries/Ada.Strings.Unbounded.Text_IO

### External examples

* Search for examples of Ada.Text_IO in: Rosetta Code, GitHub (gists), any Alire crate or this Wikibook.
* Search for posts related to Ada.Text_IO in: Stack Overflow, comp.lang.ada or any Ada related page.

### Ada Reference Manual
#### Ada 95

* A.10.1: The Package Text_IO

#### Ada 2005

* A.10.1: The Package Text_IO

#### Ada 2012

* A.10.1: The Package Text_IO

### Ada Quality and Style Guide

* 7.7.5 Current Error Files

### Open-Source Implementations

FSF GNAT
* Specification: a-textio.ads
* Body: a-textio.adb
drake
* Specification: streams/a-textio.ads
* Body: streams/a-textio.adb