June 09, 2018 [Issue 18962] New: readln() removes all '\r' characters from stdin | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=18962 Issue ID: 18962 Summary: readln() removes all '\r' characters from stdin Product: D Version: D2 Hardware: x86_64 OS: Windows Status: NEW Severity: normal Priority: P1 Component: phobos Assignee: nobody@puremagic.com Reporter: laurent.treguier.sink@gmail.com import std.conv; import std.stdio; void main() { auto line = readln(); while (!stdin.eof) { auto res = stdin.rawRead(new char[1]); if (res.length) { stdout.writeln(res[0].to!int); } } } ------------------------ This code will remove any '\r' character coming from stdin. Using any file with CRLF line endings as input, the LF part will be outputed (as its ascii code 10), but not the CR part. Commenting the `auto line = readln();` line makes `stdin.rawRead()` read '\r' characters properly; the CR part will be outputed (as its ascii code 13). This doesn't seem to occur on Linux. DMD and Phobos version : 2.080.1 -- |
Copyright © 1999-2021 by the D Language Foundation