d取文件的最后字符
myFile.seek(-1, SEEK_END);
ubyte c[1];
myFile.rawRead(c[]);
if(c[0] == '\n') // 新行结尾.
基于上个答复:
module test;
@safe:
import std;
void main()
{
File myFile = "somefile.txt";
myFile.seek(-1, SEEK_END);
ubyte[1] c;
() @trusted { myFile.rawRead(c[]); } ();
if(ControlChar.lf == c[0]) // 可移植?
writeln("是的,最后一个字符是换行符");
else
writeln("不是,最后字符不是换行符");
}
浙公网安备 33010602011771号