1. 缺少头文件 import std.string;,需要添加。
  2. 函数 stripRight 的返回值是 string,需要将其赋值给 four
  3. 函数 write 需要在输出的字符串后添加换行符 \n,或者使用 writeln 函数输出。
  4. 变量 fivesix 的定义方式有误,需要将 "< 换位,即 q"<hello\n>"q"{hello\n}"。同时,由于 stripRight 函数会修改字符串本身,需要将 fivesix 的定义放在 four 的定义之前,否则可能会影响结果。

纠正后的代码如下:

import std.stdio;
import std.algorithm;
import std.string;

void main()
{
    string one = r"hello\n
        wangzhe";
    string two = `hello\n
        wangzhe`;
    string three = q"<hello\n>"`zhenai
        jjjj`;
    string five = q"{hello\n}"`zhenai
        jjjj`;
    string six = q"{hello\n}"`zhenai
        jjjj`;

    string four = q"EOF
jjjj
EOF";
    four = four.stripRight("\n");

    write(four, "\n");
    write("tian\n");
    writeln(one, "\n", two, "\n", three, "\n", four, "\n", five, "\n", six);
}
``
dlang语言2022年以后如下代码14行报错 import stdstdio;import stdalgorithm;void main string one = rhellon wangzhe; string two = hellon wangzhe; string three = qhellonzhenai jjjj; str

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

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