Bug 3846 – Unexpected BufferedFile output

Status
RESOLVED
Resolution
WONTFIX
Severity
normal
Priority
P2
Component
phobos
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2010-02-23T17:59:00Z
Last change time
2015-06-09T01:27:41Z
Assigned to
andrei
Creator
bearophile_hugs

Comments

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(); }
Comment #2 by andy — 2015-01-27T01:06:06Z
std.stream is deprecated so closing this report.