file i/o in a variety of languages
bearophile
bearophileHUGS at lycos.com
Fri Aug 27 08:23:07 PDT 2010
Jesse Phillips:
> I'm assuming the file.open() function will close any open file. When does your suggestion close the file?
If you write:
auto f = File("foo.txt", "w");
f = File("bar.txt", "r");
I think the first file will be closed, thanks to the reference counter.
My complete version was:
import std.stdio: write, File;
void main() {
auto f = File("fileio.txt", "w");
f.writeln("hello");
f.writeln("world");
f.close();
f = File("fileio.txt", "r");
f.readln();
auto s = f.readln(); // as required
write(s);
f.close(); // optional
}
Bye,
bearophile
More information about the Digitalmars-d
mailing list