【发布时间】:2011-09-22 22:49:12
【问题描述】:
我在将字符串变量写入文件时遇到了一些问题。 问题是我必须指定该字符串的确切长度。否则输出文件将只包含一些废品值。我想知道是否可以以某种方式解决这个问题而无需事先告知字符串的长度?
我知道我的Get() 过程存储了该变量的长度,我可以将它返回给主程序。但是我想编写我的程序,以便在我开始写入输出文件之前先从输入文件中读取所有内容。
with Ada.Text_Io, Ada.Integer_Text_Io;
use Ada.Text_Io,Ada.Integer_Text_Io;
procedure Uppgift is
type Bil_Register is
record
Namn : String(1..50);
Adress : String(1..50);
Post : String(1..50);
Reg : String(1..6);
end record;
Infil : File_Type;
Utfil : File_Type;
L, I : Integer;
Br : Bil_Register;
procedure Get(F : in out File_Type; Br : out Bil_Register) is
Length : Integer;
begin
Get_Line(F, Br.Namn, Length);
end;
begin
Open(Infil, In_File, "register.txt");
Create(Utfil, Out_File, "test.txt");
Get(Infil, Br);
Put_Line(Utfil, Br.Namn);
Close(Infil);
Close(Utfil);
end Uppgift;
-
编辑 (2011.08.20)
这似乎只是基于 Unix 的操作系统的问题。在使用 Windows 时,当您将其打印到文件或屏幕时,您不必绝对使用字符串大小
【问题讨论】: