ウィキのコピーミラー

これは pascal.chat のウィキのミラーです。編集、履歴、ログインはそちらで行います。

Text/ja

English · Русский · 日本語

TextFile変数(古い形式のTextに相当する)は、テキストファイルの読み書きに用います。

pascal
{$mode objfpc}{$H+}
var 
  MyFile: TextFile;
  s: string;
begin
  AssignFile(MyFile, 'a.txt');
  try
    reset(MyFile); 
    readln(MyFile, s);
    writeln('Text read from file: ', s)

  finally
    CloseFile(MyFile)
  end
end.

テキストファイルを表現する変数(上記例ではMyFile)によって、実際のテキストファイルに対する読み込みおよび書き込みを実行できます。テキストファイル変数は、run-time libraryのAssignFileを用いて実際のファイルと関連付ける必要があります。そして、ファイルを開くにはResetやRewrite、またはAppendプロシージャを用います。ファイルの読み書きには、Read、Readln、Write、Writelnを使います。ファイルの処理が終わったら、ファイルリソースを解放するためにCloseFileを呼び出して、ファイルをクローズする必要があります。

注意:TextFile変数は、file of charの変数とは全く異なります。:


From the Free Pascal wiki, page "Text/ja", as it stood on 2020-02-29 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

第1版、最終更新:WikiArchive 。