简体   繁体   中英

Ada: How to read variable length strings from command line

I am doing a multi-stack program with opcodes that look like the following:

I2 Sam
I3 Bobby
I1 Steve
D3
I3 Jonathan

"I" means insert and the number is which stack, "D" means to delete and number is which stack. My question is, how do I read each of these from the command line and determine which operation to perform? The names are of variable length, and I cannot use heap memory. The one thing I can do is, since the list of possible names is known, is make the names into an enumeration type. Thanks!

If you are reading the values from standard input and are using at least Ada 2005, this method will work:

with Ada.Text_IO;

procedure Foo is
   use Ada.Text_IO;
begin
   while not End_Of_File loop
      declare
         Cur_Line : constant String := Get_Line;
      begin
         -- process the line here
      end;
   end loop;
end Foo;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM