Ada中的多行字符串文字

Tam*_*inn 1 string ada multiline literals

如何在Ada中创建一个包含换行符的字符串,其定义也包含这些换行符?

我尝试在行尾使用0..2反斜杠,但是没有一个可以编译:

   usage_info : String := "\
This should be the first line
and both the definition and the output
should contain newlines.";
Run Code Online (Sandbox Code Playgroud)

在PHP中,这将是:

<<<BLOCK
1
2
3
BLOCK;
Run Code Online (Sandbox Code Playgroud)

在C ++中,这将是:

const std::string s = "\
1
2
3";
Run Code Online (Sandbox Code Playgroud)

在C#中,它将是:

const string s =
@"1
2
3";
Run Code Online (Sandbox Code Playgroud)

Fré*_*aca 6

据我了解,Ada与Java一样,不支持多行文字。我唯一看到的是这样的:

usage_info : String := "This should be the first line" & CR & LF
                     & "and both the definition and the output" & CR & LF 
                     & "should contain newlines.";
Run Code Online (Sandbox Code Playgroud)

当然,您需要使用使用 Ada.Characters.Latin_1来使这些常量可见。

  • 请参见[ARM 2.6(7)](http://www.ada-auth.org/standards/rm12_w_tc1/html/RM-2-6.html#p7),“行尾不能出现在string_literal中”。 (4认同)