write to file ... trivial?

Denis Koroskin 2korden at gmail.com
Wed Oct 6 11:59:40 PDT 2010


On Wed, 06 Oct 2010 22:43:42 +0400, Dr. Smith <iam at far.out> wrote:

> This should be trivial.  However, I've not found in the documentation  
> (trying
> both std.stdio and std.file) how to write to a file in the manner here:
>
> filename.writefln("%s\t%f", someString, someDouble);
>
> ... this merely prints filename to screen ... does not create a data  
> file.

In your case, foo.bar(args) == bar(foo, args) - that is call Uniform  
Function Call Syntax, that is:

filename.writefln("%s\t%f", someString, someDouble); -> writefln(filename,  
"%s\t%f", someString, someDouble);

which in turn tries using filename as a format.

Try using std.stream. It should be something like this:

File file = new File(fileName, FileMode.OutNew); // open file for writing,  
create new if none exists
file.writefln("hello, %s!", "world");

Not tested but should work.


More information about the Digitalmars-d-learn mailing list