How do I create a new file using phobos ?

Bill Baxter dnewsgroup at billbaxter.com
Fri Sep 21 14:45:35 PDT 2007


Bill Baxter wrote:
> Ray C Horn wrote:
>> How do I create a new file using phobos ?
>>
>> More examples in the online docs would be useful.
> 
> You can do it several ways.
> 
> Theres std.c.stdio which has the classic C fopen/fclose API.
> 
> I usually use std.stream.BufferedFile
> http://www.digitalmars.com/d/phobos/std_stream.html
> 
> Ex:
> char[][] lines;
> ...
> {
>     scope Stream file = new BufferedFile("sample.txt",FileMode.Out);
>     foreach(line; lines) {
>        file.writefln(line);
>     }
> }

Wait a minute, can anyone confirm that it's ok to use a scope 
BufferedFile without explicitly closing?
BufferedFile contiains a 'new File()', but no destructor.  The File's 
destructor contains a close(), however.  So will the member File's 
destructor get called when the scope BufferedFile goes out of scope?

It's really just a question of how scope works w.r.t classes with heap 
allocated members.  Do the reference members get deleted 
deterministically on scope exit too?

--bb



More information about the Digitalmars-d mailing list