Re: readln with buffer fails

2014-10-29 Thread dcrepid via Digitalmars-d-learn
On Wednesday, 29 October 2014 at 23:28:07 UTC, Justin Whear wrote: Part of what readln does is *modify* the slice itself, not just the pointed-to characters. In particular it alters the length member so that you know how much input was actually read. This is also why the rvalue reference sho

Re: readln with buffer fails

2014-10-29 Thread Justin Whear via Digitalmars-d-learn
On Wed, 29 Oct 2014 23:10:10 +, dcrepid wrote: > On Wednesday, 29 October 2014 at 21:19:25 UTC, Peter Alexander wrote: >> You need to take a slice of the buffer: >> >> char[] buf = Input[]; >> readln(buf); >> // line now in buf >> >> The reason for this is because you need to know where the st

Re: readln with buffer fails

2014-10-29 Thread dcrepid via Digitalmars-d-learn
lol, if only I could edit my posts. The comment preceding the readln() call was wrong too. This is what I have now: // readln(buf) requires a slice *Reference*. // rvalue references aren't supported by D, so readln(Input[]) fails

Re: readln with buffer fails

2014-10-29 Thread dcrepid via Digitalmars-d-learn
err, I meant rvalue *reference* above

Re: readln with buffer fails

2014-10-29 Thread dcrepid via Digitalmars-d-learn
On Wednesday, 29 October 2014 at 21:19:25 UTC, Peter Alexander wrote: You need to take a slice of the buffer: char[] buf = Input[]; readln(buf); // line now in buf The reason for this is because you need to know where the string ends. If you just passed in Input, how would you know how long t

Re: readln with buffer fails

2014-10-29 Thread ketmar via Digitalmars-d-learn
On Wed, 29 Oct 2014 21:14:13 + dcrepid via Digitalmars-d-learn wrote: > Now, I'm used to 'buffer' meaning one thing, but here it seems > that buffer means something more akin to a 'sink' object, or a > forced dynamic array type? Is there some way I can avoid dynamic > allocations? take a

Re: readln with buffer fails

2014-10-29 Thread Baz via Digitalmars-d-learn
On Wednesday, 29 October 2014 at 21:14:17 UTC, dcrepid wrote: I have this simple code: int main() { import std.stdio; char[4096] Input; readln(Input); //readln!(char)(Input); // also fails return 0; } I get these messages during compilation: test.d(39): Error: template std.s

Re: readln with buffer fails

2014-10-29 Thread Peter Alexander via Digitalmars-d-learn
You need to take a slice of the buffer: char[] buf = Input[]; readln(buf); // line now in buf The reason for this is because you need to know where the string ends. If you just passed in Input, how would you know how long the line read was?

readln with buffer fails

2014-10-29 Thread dcrepid via Digitalmars-d-learn
I have this simple code: int main() { import std.stdio; char[4096] Input; readln(Input); //readln!(char)(Input); // also fails return 0; } I get these messages during compilation: test.d(39): Error: template std.stdio.readln cannot deduce function from argument types !()(ch