Dlang DMD2 BetterC 模式下使用字符串字面量初始化 char 数组
以下是一个可以运行的例子:
import core.stdc.string;
void main()
{
// 使用字符串字面量快速初始化 char 数组
char[] str = 'hello, world!';
// 打印输出 char 数组
printf('%s\n', str.ptr);
}
在上面的例子中,我们使用了字符串字面量来初始化一个 char 数组。注意,在 BetterC 模式下,我们需要手动导入 core.stdc.string 模块来使用 printf 和 strcpy 等 C 语言标准库函数。
在程序运行时,会输出以下结果:
hello, world!
原文地址: https://www.cveoy.top/t/topic/n1Qs 著作权归作者所有。请勿转载和采集!