在D中将auto(字符串)转换为char

Sul*_*man 2 d

对于使用foreach循环进行迭代并获取文件的日期,我需要将其作为输入char [],但不是字符串.

我写了下一个代码:

auto files = dirEntries ("E:\\ddd", SpanMode.shallow);

foreach (file; files)
{
    char [] s = to!char[](file); //it's crap... and do not work...
    writeln(file);

}
Run Code Online (Sandbox Code Playgroud)

我使用下一个方法http://dlang.org/phobos/std_file.html#.getTimes 需要输入char [] :(在char []名称中)

Mih*_*uns 7

要获得不可变数组的可变副本,您可以使用.dup:

char[] s = file.dup;
Run Code Online (Sandbox Code Playgroud)

但是在您的情况下,您不需要进行任何转换.getTimes接受in char[]哪个是快捷方式scope const char[].将不可变数组作为const参数传递是完全合法的,因此它应该"正常工作".