Comment #0 by bearophile_hugs — 2010-02-23T17:59:12Z
This D2 code:
import std.stream: BufferedFile, FileMode;
import std.conv: to;
void main() {
auto fout = new BufferedFile("foo.txt", FileMode.Out);
int x = 10;
fout.write(to!(const(char)[])(x) ~ "\n");
fout.close();
}
Generates this foo.txt file (bytes expressed in hex):
03 00 00 00 31 30 0a
This Python2.6 program:
fout = file("foo.txt", "w")
fout.write(str(10) + "\n")
Generates this foo.txt file:
31 30 0d 0a
So I don't know if the D code gives the right output.
---------------
Secondary problem, this line:
fout.write(to!(const(char)[])(x) ~ "\n");
can't be replaced by this simpler one, that doesn't work:
fout.write(to!string(x) ~ "\n");
Comment #1 by bearophile_hugs — 2010-10-29T17:33:10Z
The second problem is now fixed, this code compiles, see bug 2718 :
import std.stream: BufferedFile, FileMode;
import std.conv: to;
void main() {
auto fout = new BufferedFile("foo.txt", FileMode.Out);
int x = 10;
fout.write(to!string(x) ~ "\n");
fout.close();
}