Writing to two files at once

wobbles via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu May 21 14:11:49 PDT 2015


On Thursday, 21 May 2015 at 21:02:42 UTC, Ali Çehreli wrote:
> On 05/21/2015 01:56 PM, wobbles wrote:
>
>> What I ended up doing was creating an OutputRange that 
>> contains the
>> files I want to write to.
>> On OutputRange.put I simply print to print to all the files.
>
> Just like MultiFile example here: :)
>
>   http://ddili.org/ders/d.en/ranges.html#ix_ranges.OutputRange
>
> Ali

Yeah!
This is my implementation:
public struct OutputSink{
	File[] files;
	@property void addFile(File f){ files ~= f; }
	@property File[] file(){ return files; }

	void put(Args...)(string fmt, Args args){
		foreach(file; files)
			file.writefln(fmt, args);
	}
}

I'll remember to look in your book next time I need something 
simple :)


More information about the Digitalmars-d-learn mailing list