我正在 Eiffel 中开发一个程序,该程序从输入文件读取数据,对其进行处理,然后将结果写入输出文件。输入文件包含:ID、姓名、出生日期、地址和家庭成员人数。该计划根据年龄和家庭成员人数计算经济援助。
但是,我遇到了错误:
功能调用中的实际参数不兼容
当我尝试使用 split 方法来分隔输入文件行中的值时,会发生此错误。
这是我的埃菲尔代码
class
PERSON_ASSISTANCE
create
make
feature {NONE} -- Initialization
make
local
input_file, output_file: PLAIN_TEXT_FILE
id, name, birthdate, address: STRING
family_members_count: INTEGER
current_year, birth_year, age, financial_assistance: INTEGER
line: STRING
do
create input_file.make_open_read("input.txt")
create output_file.make_open_write("output.txt")
-- Read input file line by line
current_year := 2024
from
input_file.read_line
until
input_file.end_of_file
loop
line := input_file.last_string
-- This is where I encounter the error
id := line.split(",").item(1) -- Error occurs here
name := line.split(",").item(2)
birthdate := line.split(",").item(3)
address := line.split(",").item(4)
family_members_count := line.split(",").item(5).to_integer
-- Extract birth year and calculate age
birth_year := birthdate.substring(1, 4).to_integer
age := current_year - birth_year
-- Calculate financial assistance
financial_assistance := (age * 10) + (family_members_count * 10)
-- Write result to output file
output_file.put_string(id + ", " + name + ", " + financial_assistance.out + "€%N")
input_file.read_line
end
input_file.close
output_file.close
end
end
当我尝试调用 split(",") 时发生错误