On Wed, 18 Apr 2012 14:09:20 +0200, Paul <[email protected]> wrote:

I copied the code below from this site under the std.stdio library reference section and tried to compile it. I downloaded D2/Phobos. Compiler says "fileread.d(4): Error: undefined identifier File"

If I add import std.stdio to the beginning it get ; expected, function declaration w/o return type, etc.

Assistance is greatly appreciated.

  void main(string args[])
{
     auto f = File("test.txt", "w"); // open for writing
     f.write("Hello");
     if (args.length > 1)
     {
         auto g = f; // now g and f write to the same file
                     // internal reference count is 2
         g.write(", ", args[1]);
         // g exits scope, reference count decreases to 1
     }
     f.writeln("!");
     // f exits scope, reference count falls to zero,
     // underlying FILE* is closed.
}

As you note, File is a part of stdio. I think you might have forgotten to terminate the import statement with a semicolon.
The following should work:

import std.stdio;
void main() {
    auto f = File("test.txt", "w");
    f.write("Hello");
}

Reply via email to