Ada 除了布尔运算符外and then,还具有if条件中使用的语句的出色功能。这允许在访问对象之前检查例如该对象是否不为null,如下所示:and
if Object /= null and then Object.Value > 5 then
-- do something with the value
end if;
Run Code Online (Sandbox Code Playgroud)
有没有一种方法可以使用嵌套在C ++ w / o中表达类似的行为if?
我有一段代码(见下文)从作为命令行参数给出的文件中读取数据。我想添加对能够从管道读取输入的支持。例如,当前版本将数据读取为main <file_name>,而它也应该可以做一些 line cmd1 | main。这是从文件中读取数据的来源:
procedure main is
File : Ada.Text_IO.File_Type;
begin
if Ada.Command_Line.Argument_Count /= 1 then
return;
else
Ada.Text_IO.Open (
File => File,
Mode => In_File,
Name => Ada.Command_Line.Argument (1));
while (not Ada.Text_IO.End_Of_File (File)) loop
-- Read line using Ada.Text_IO.Get_Line
-- Process the line
end loop;
Ada.Text_IO.Close (File);
end main;
Run Code Online (Sandbox Code Playgroud)
如果我理解正确的话,管道只是 Ada 中的一种非常规文件类型。但是我该如何处理呢?