在D语言中,数组类型没有内置的reverse()方法。可以使用std.algorithm.reverse()函数来实现数组的反转。因此,你需要在代码中添加std.algorithm模块的引用,并将数组类型改为可变数组类型(MutableArray)才能使用该函数。

正确的代码如下:

import std.stdio; import std.algorithm;

void main() { int[] one = [1,2,3]; int[] two = one[$-2..$]; reverse(two); writeln(one, two); }

dlang语言dmd2103版本以下代码报错提示:Error no property reverse for two of type int我的代码如下:import stdstdio;void main int3 one = 123; int two = one$-2$; tworeverse; writelnonetwo;请帮我纠正给出正确代码

原文地址: https://www.cveoy.top/t/topic/e9b9 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录