Reputation: 395
In Ada, can you open, write to, close, then reopen, write to, and close a txt file without it being overwritten? Like continue from where it last left off? Thanks!
Upvotes: 1
Views: 240
Reputation: 6601
Yes. If you look in section A.10.1 in the reference manual, you can see that the package Ada.Text_IO
includes the declaration:
type File_Mode is (In_File, Out_File, Append_File);
Append_File
is the mode you are looking for.
A.10.2(3) in the reference manual requires that you get a new line, when you close a file:
For the procedure
Close
: If the file has the current modeOut_File
orAppend_File
, has the effect of callingNew_Page
, unless the current page is already terminated; then outputs a file terminator.
... where A.10.5(16) explains what New_Page
does:
Operates on a file of mode
Out_File
orAppend_File
. Outputs a line terminator if the current line is not terminated, or if the current page is empty (that is, if the current column and line numbers are both equal to one). Then outputs a page terminator, which terminates the current page. Adds one to the current page number and sets the current column and line numbers to one.
If you want more detailed control over what ends up in a file, you should use one of the other I/O packages.
Upvotes: 4