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("不是,最后字符不是换行符");

}
posted @ 2023-02-15 20:51  zjh6  阅读(15)  评论(0)    收藏  举报  来源