在调用file2.detach()后,file2和example.txt文件的关联被分离了,但是example.txt文件仍然被file1所关联。在调用file1.readln()时,它尝试读取example.txt文件,但是由于在之前的file2.detach()中,example.txt文件已经与file2的关联被分离了,所以此时读取example.txt文件的操作会失败,从而导致了std.stdio.StdioException异常的抛出。因此,调用file2.detach()后,需要确保在读写example.txt文件时只使用与之关联的File对象(即file2),而不是其他对象(如file1)。

我有以下dlang语言代码import stdstdio;void main auto file1 = Fileexampletxt w; file1writelnHello world!; auto file2 = Fileexampletxt r; writelnfile2name; 输出 exampletxt writelnfile2eof; 输出 fals

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

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