Programming I / O File D

I am trying to execute a simple tutorial and cannot get the following code to work:

void main(string args[])
{
  auto f = File("test.txt", "w");
  f.writeln("Hello, Worlds!");
}

I am using dmd compiler for windows.

+3
source share
1 answer

If you are using D2, you need to import std.stdio;:

import std.stdio;
void main(string args[])
{
  auto f = File("test.txt", "w");
  f.writeln("Hello, Worlds!");
}

If you use D1, the class Fileis in std.stream, and the API is slightly different:

import std.stream;
void main() {
  auto f = new File("test.txt", FileMode.Out);
  f.writeLine("Hello, Worlds!");
}
+18
source

Source: https://habr.com/ru/post/1760690/


All Articles