Sorry for my previous answer, I missed that the file you were reading was one you created earlier in the program.
In Ada.Text_IO
, the RM (A.10(7-8)) says "the end of a file is marked by the combination of a line terminator immediately followed by a page terminator and then a file terminator", and "The actual nature of terminators is not defined by the language and hence depends on the implementation" ... "they are not necessarily implemented as characters or as sequences of characters". So when you create say_something_test.txt
, it will always end with a "line terminator" although that doesn't necessarily mean it will end with an LF. That's implementation-dependent. The only thing you're guaranteed is that if you use Ada.Text_IO
to create a file, it will work correctly if you read it back in with Ada.Text_IO
. But if you want this level of control of the actual bytes written to the file, then Ada.Text_IO
would not really be suitable; you'd be better off using Ada.Stream_IO
.
Whether an CR and/or LF is written to the end of the file is implementation-dependent. It looks like GNAT does add LF (and maybe CR) to the end, and it doesn't provide a way (such as a Form
parameter) to turn this behavior off. At least I didn't see one in the manual.
If you're really determined to use Ada.Text_IO
to write say_something_test.txt
and Ada.Direct_IO
to read it back in, then you need to be aware that the file may or may not contain CR/LF, and the input routine should check for those characters and strip them off so that the string can be compared to the expected value.