write to file ... trivial?

Seth Hoenig seth.a.hoenig at gmail.com
Wed Oct 6 12:22:04 PDT 2010


Here's a minimal little template (checked):

import std.stdio;

void main()
{
        auto f = File("outfile.txt", "w");
        f.writefln("%s World", "Hello");
        f.close();
}





2010/10/6 Denis Koroskin <2korden at gmail.com>

> 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.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20101006/f038cf33/attachment.html>


More information about the Digitalmars-d-learn mailing list