D语言新手问题 文本读取

· Created · Last modified by size_t replied at · 932 times read

找了半天文档解决了,把while循环条件变下

	string line;
	while( ( line=strip(file.readln()) ) !is null ) 
	{
		writeln("read line |", line);
	}

遍历文本时多出一行空行,怎么避免呢?

import std.stdio;
import std.string;

void main(string[] args) {

	if(args.length !=2){
		writeln(args[0],"\t<file>");
		return;
	}

	File file = File(args[1],"r");

	while(!file.eof()) 
	{
		string line = strip(file.readln());
		writeln(line);
	}
}

Login to reply