Hey guys.
I just want to write a few console applications. Usualy I have to read numbers
to calculate some values. But what's the smartest way to read and convert the
input?
I've coded these lines:
import std.stdio, std.string, std.conv;
T readNumber(T)()
{
string buffer;
import std.stdio;
T readNumber(T)()
{
T result;
stdin.readf(%s, result);
return result;
}
Throws a ConvException if the input string wasn't in the right format.
On 10 November 2011 22:48, Fabian talk2...@online.de wrote:
Hey guys.
I just want to write a few console applications.
This: https://github.com/he-the-great/JPDLibs/tree/cmdln/cmdln
The HTML docs explain how to use it. Not mine, but I think this would
be a sweet addition to Phobos imo.
Thanks a lot. That's exactly what I was searching for.
Andrej Mitrovic wrote:
This: https://github.com/he-the-great/JPDLibs/tree/cmdln/cmdln
The HTML docs explain how to use it. Not mine, but I think this would
be a sweet addition to Phobos imo.
Thank you. :)
On Thursday, November 10, 2011 13:48 Fabian wrote:
Hey guys.
I just want to write a few console applications. Usualy I have to read
numbers to calculate some values. But what's the smartest way to read and
convert the input?
I've coded these lines:
import std.stdio, std.string,
I don't get the exception on Linux after a new line, I have to wait
until EOF, which is typically the end of the program if reading from
STDIN. Not very useful.
import std.stdio;
T readNumber(T)()
{
T result;
stdin.readf(%s, result);
return result;
}
void main()
{
try
{
Yes, you are right. You can make it work by changing to line buffering:
stdin.setvbuf(null, _IOLBF);
But at that point, another solution (like using std.conv.to) is
probably the better choice.
On 10 November 2011 23:40, Kai Meyer k...@unixlords.com wrote:
I don't get the exception on Linux
Ok - Good to know. Thank you ;)