[英]Initialize string in Ada with null characters
I am new to Ada, I need to make initialize a string with null characters, how can I do it? 我是Ada的新手,我需要使用空字符初始化一个字符串,该怎么办? So far I can initialize a string with spaces as follows: 到目前为止,我可以使用空格初始化字符串,如下所示:
user_str : String(1..50) := (others => ' ');
user_str : String(1..50) := (others => Character'Val(0));
or 要么
user_str : String(1..50) := (others => Ada.Characters.Latin_1.NUL);
Unlike some other languages, Ada does not have a special syntax for embedding speclal characters in character or string literals (like C's '\\0'
, for example). 与其他一些语言不同,Ada没有在字符串或字符串文字中嵌入特殊字符的特殊语法(例如C的'\\0'
)。
(Of course the latter requires an appropriate with
clause.) (当然,后者需要一个适当的with
子句。)
尝试:
user_str : String(1..50) := (others => ascii.nul);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.