D文件I/O功能

Gra*_*lls 7 io d file

我刚刚学习D.看起来像一个很棒的语言,但我找不到任何有关文件I/O功能的信息.我可能很朦胧(我很擅长那个!),所以有人能指出我正确的方向吗?谢谢

ken*_*ytm 10

基本上,您使用File结构std.stdio.

import std.stdio;

void writeTest() {
    auto f = File("1.txt", "w");        // create a file for writing,
    scope(exit) f.close();              //   and close the file when we're done.
                                        //   (optional)
    f.writeln("foo");                   // write 2 lines of text to it.
    f.writeln("bar");
}

void readTest() {
    auto f = File("1.txt");             // open file for reading,
    scope(exit) f.close();              //   and close the file when we're done.
                                        //   (optional)
    foreach (str; f.byLine)             // read every line in the file,
      writeln(":: ", str);              //   and print it out.
}

void main() {
   writeTest();
   readTest();
}
Run Code Online (Sandbox Code Playgroud)


Joe*_*oey 3

模块怎么样std.stdio