[Issue 18962] New: readln() removes all '\r' characters from stdin
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Jun 9 18:35:38 UTC 2018
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 at puremagic.com
Reporter: laurent.treguier.sink at 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
--
More information about the Digitalmars-d-bugs
mailing list