수색…


소개

하위 유형 속성 'Image'Value 는 각각 스칼라 값과 문자열을 취하며 각각 문자열과 스칼라 값을 반환합니다. 'Image 'Value'Value 입력하여 원래 값을 얻을 수 있습니다. 그 반대도 마찬가지입니다.

__Scalar_Object__'Image 속성은 Ada 2012-TC-1부터 객체에 직접 사용할 수 있습니다.

통사론

  • 함수 Scalar'Image (인수 : Scalar'Base)는 문자열을 반환합니다.
  • 함수 Discrete'Image (인수 : Discrete'Base) 반환 문자열;
  • function Integer'Image (Argument : Integer'Base) 반환 문자열;
  • function Enumeration'Image (Argument : Enumeration'Base) 반환 문자열;
  • 함수 Real'Image (인수 : Real'Base) 반환 문자열;
  • function Numeric'Image (Argument : Numeric'Base) 반환 문자열;
  • 함수 Scalar'Value (인수 : 문자열) 반환 Scalar'Base;
  • 함수 Discrete'Value (인수 : 문자열) return Discrete'Base;
  • function Integer'Value (인수 : 문자열) return Integer'Base;
  • function Enumeration'Value (Argument : String) return Enumeration'Base;
  • 함수 Real'Value (인수 : 문자열) return Real'Base;
  • 함수 Scalar_Object '이미지 반환 문자열;

비고

'Image 는 구현 정의 결과 (RM 3.5), 즉 String 결과에 필요한 일부 그래픽 문자가 Character 정의되지 않은 경우 발생할 수 있습니다. 'Wide_Image 'Wide_Wide_Image'Wide_Wide_Image 'Wide_Image 의 더 큰 레퍼토리를 고려하십시오.

Ada 2012 (TC-1)

__Scalar_Object__'Image 속성을 사용할 권한이 Ada 2012-TC-1 (2016 년 4 월)에 개체에 직접 추가되었습니다.

Image 속성을 사용하여 float 출력

Ada 2012 (TC-1)
with Ada.Text_IO;

procedure Main is
   type Some_Float digits 8 range 0.0 .. 10.0;
   X : Some_Float := 2.71;
begin
   Ada.Text_IO.Put_Line (X'Image);
end Main;

결과

2.71000E+00

Image 속성을 사용하여 정수 출력

Ada 2012 (TC-1)
with Ada.Text_IO;

procedure Main is
   type Some_Integer is range -42 .. 42;
   X : Some_Integer := 17;
begin
   Ada.Text_IO.Put_Line (X'Image);
end Main;

결과

17

Image 특성을 사용하여 열거 형을 인쇄하십시오.

Ada 2012 (TC-1)
with Ada.Text_IO;

procedure Main is
   type Fruit is (Banana, Orange, Pear);
   X : Fruit := Orange;
begin
   Ada.Text_IO.Put_Line (X'Image);
   Ada.Text_IO.Put_Line (Pear'Image);
end Main;

결과

ORANGE
PEAR

속성 Image를 사용하여 열거 형을 인쇄하십시오.

with Ada.Text_IO;

procedure Main is
   type Fruit is (Banana, Orange, Pear);
   X : Fruit := Orange;
begin
   Ada.Text_IO.Put_Line (Fruit'Image (X));
end Main;

결과

ORANGE

속성 Image를 사용하여 정수 출력

with Ada.Text_IO;

procedure Main is
   X : Integer := 17;
begin
   Ada.Text_IO.Put_Line (Integer'Image (X));
end Main;

결과

17

속성 Image를 사용하여 플로트 인쇄

with Ada.Text_IO;

procedure Main is
   X : Float := 2.71;
begin
   Ada.Text_IO.Put_Line (Float'Image (X));
end Main;

결과

2.71000E+00

역으로

with Ada.Text_IO;

procedure Image_And_Value is
   type Fruit is (Banana, Orange, Pear);
   X  : Fruit := Orange;
begin
   Ada.Text_IO.Put_Line (Boolean'Image
      (Fruit'Value (Fruit'Image (X)) = X
          and
       Fruit'Image (Fruit'Value ("ORANGE")) = "ORANGE"));
end Image_And_Value;

결과

TRUE


Modified text is an extract of the original Stack Overflow Documentation
아래 라이선스 CC BY-SA 3.0
와 제휴하지 않음 Stack Overflow