Ada:多次写入文件
Ada: Write to File Multiple Times
在 Ada 中,您可以打开、写入、关闭然后重新打开、写入和关闭 txt 文件而不被覆盖吗?就像从上次中断的地方继续?
谢谢!
是的。如果您查看参考手册中的 A.10.1 节,您可以看到包 Ada.Text_IO
包含声明:
type File_Mode is (In_File, Out_File, Append_File);
Append_File
就是你要找的模式
参考手册中的 A.10.2(3) 要求您在关闭文件时换行:
For the procedure Close
: If the file has the current mode Out_File
or Append_File
, has the effect of calling New_Page
, unless the current page is already terminated; then outputs a file terminator.
... 其中 A.10.5(16) 解释了 New_Page
的作用:
Operates on a file of mode Out_File
or Append_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.
如果您想更详细地控制文件中的内容,您应该使用其他 I/O 包之一。
在 Ada 中,您可以打开、写入、关闭然后重新打开、写入和关闭 txt 文件而不被覆盖吗?就像从上次中断的地方继续? 谢谢!
是的。如果您查看参考手册中的 A.10.1 节,您可以看到包 Ada.Text_IO
包含声明:
type File_Mode is (In_File, Out_File, Append_File);
Append_File
就是你要找的模式
参考手册中的 A.10.2(3) 要求您在关闭文件时换行:
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.
... 其中 A.10.5(16) 解释了 New_Page
的作用:
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.
如果您想更详细地控制文件中的内容,您应该使用其他 I/O 包之一。