digitalmars.D.learn - simple console input's not working...
- SodiumFree (15/15) Jun 05 2008 So i copy this code, pretty much straight from the book (page 139):
- predaeus (11/14) Jun 06 2008 From:
- Tower Ty (6/23) Jun 06 2008 I don't blame you if you are confused , so am I .
- SodiumFree (1/1) Jun 06 2008 Ah, thanks for the link to the docs too, was wondering where they were l...
- Tower Ty (10/32) Jun 06 2008 While we wait this at least compiles but it is meaningless
- Tower Ty (12/34) Jun 06 2008 Here is another one with an output
- Mike Parker (30/52) Jun 06 2008 Cin.readln (which is the method tango.io.Console.Console.Input.readln)
- Tower Ty (11/70) Jun 06 2008 Good Mike , and this goes too
- SodiumFree (1/1) Jun 06 2008 Thanks, both examples make the explanation a lot clearer. Rather strange...
- Jarrett Billingsley (6/8) Jun 06 2008 It's probably because Tango is not complete, and has been in a constant
- Robert Fraser (6/15) Jun 06 2008 I know it's in alpha, but I really wish the Tango devs (and Phobos, too)...
- Steven Schveighoffer (12/20) Jun 09 2008 I don't have a copy of the book, but I think it is just a book typo.
So i copy this code, pretty much straight from the book (page 139): module inputTest; import tango.io.Console; void main(){ Cout("What is your name? ").flush; auto name = Cin.readln; Cout("Hello ")(name).newline; } However when i try compiling, dmd spits out this error: C:\d.stuff\inputTest>dmd inputTest.d inputTest.d(6): function tango.io.Console.Console.Input.readln (char[],bool) does not match parameter types () inputTest.d(6): Error: expected 2 arguments, not 0 inputTest.d(7): function alias tango.io.Console.Console.Output.append (char[]) does not match parameter types (bool) inputTest.d(7): Error: expected 0 arguments, not 1 Any idea what's going on?
Jun 05 2008
SodiumFree Wrote:inputTest.d(6): function tango.io.Console.Console.Input.readln (char[],bool) does not match parameter types () ... Any idea what's going on?From: http://www.dsource.org/projects/tango/docs/current/tango.io.Console.html " ... Retreive a line of text from the console and map it to the given argument. The input is sliced, not copied, so use .dup appropriately. Each line ending is removed unless parameter raw is set to true. Returns false when there is no more input. ... " So, the syntax of readln is a bit different. You have to pass it the string that will hold the data.
Jun 06 2008
predaeus Wrote:SodiumFree Wrote:I don't blame you if you are confused , so am I . It should be pretty simple at this level and the book examples should at least work . They sometimes don't and I'm buggered if I can understand why. The guy that answers certainly does not put it clearly Lets hope some kind soul drops in and explains it to both of us !inputTest.d(6): function tango.io.Console.Console.Input.readln (char[],bool) does not match parameter types () ... Any idea what's going on?From: http://www.dsource.org/projects/tango/docs/current/tango.io.Console.html " ... Retreive a line of text from the console and map it to the given argument. The input is sliced, not copied, so use .dup appropriately. Each line ending is removed unless parameter raw is set to true. Returns false when there is no more input. ... " So, the syntax of readln is a bit different. You have to pass it the string that will hold the data.
Jun 06 2008
Ah, thanks for the link to the docs too, was wondering where they were located.
Jun 06 2008
SodiumFree Wrote:So i copy this code, pretty much straight from the book (page 139): module inputTest; import tango.io.Console; void main(){ Cout("What is your name? ").flush; auto name = Cin.readln; Cout("Hello ")(name).newline; } However when i try compiling, dmd spits out this error: C:\d.stuff\inputTest>dmd inputTest.d inputTest.d(6): function tango.io.Console.Console.Input.readln (char[],bool) does not match parameter types () inputTest.d(6): Error: expected 2 arguments, not 0 inputTest.d(7): function alias tango.io.Console.Console.Output.append (char[]) does not match parameter types (bool) inputTest.d(7): Error: expected 0 arguments, not 1 Any idea what's going on?While we wait this at least compiles but it is meaningless module test4; import tango.io.Console; void main(){ Cout("What is your name? ").flush; char[] message= "What is your pleasure?"; auto name = Cin.readln(message); Cout("Hello ").newline; }
Jun 06 2008
SodiumFree Wrote:So i copy this code, pretty much straight from the book (page 139): module inputTest; import tango.io.Console; void main(){ Cout("What is your name? ").flush; auto name = Cin.readln; Cout("Hello ")(name).newline; } However when i try compiling, dmd spits out this error: C:\d.stuff\inputTest>dmd inputTest.d inputTest.d(6): function tango.io.Console.Console.Input.readln (char[],bool) does not match parameter types () inputTest.d(6): Error: expected 2 arguments, not 0 inputTest.d(7): function alias tango.io.Console.Console.Output.append (char[]) does not match parameter types (bool) inputTest.d(7): Error: expected 0 arguments, not 1 Any idea what's going on?Here is another one with an output module test4; import tango.io.Console; void main(){ Cout("What is your name? ").flush; char[] name; Cin.readln(name); name~= "Hello "; Cout(name).newline; } Strange
Jun 06 2008
SodiumFree wrote:So i copy this code, pretty much straight from the book (page 139): module inputTest; import tango.io.Console; void main(){ Cout("What is your name? ").flush; auto name = Cin.readln; Cout("Hello ")(name).newline; } However when i try compiling, dmd spits out this error: C:\d.stuff\inputTest>dmd inputTest.d inputTest.d(6): function tango.io.Console.Console.Input.readln (char[],bool) does not match parameter types () inputTest.d(6): Error: expected 2 arguments, not 0 inputTest.d(7): function alias tango.io.Console.Console.Output.append (char[]) does not match parameter types (bool) inputTest.d(7): Error: expected 0 arguments, not 1 Any idea what's going on?Cin.readln (which is the method tango.io.Console.Console.Input.readln) expects at least one argument -- a string in which to store the input. You've given it nothing. The compiler reports this in the first error, then keeps on compiling. Second, 'name' is automatically inferred as a bool and not as a string as you seem to intend it to be. You'll see in the documentation that readln returns true if input is read and false if not. So the compiler sees you trying to pass a bool value in the call to Cout when it expects a string, resulting in the second error. A look at the source for tango.io.Console should make the error messages more clear. Console is a struct with the inner classes Input and Output. Cin is an instance of Console.Input. Hence the tango.io.Console.Console.Input.readln (char[],bool) in the error string. In Console.output, the append method is aliased to opCall. That's what allows the COut()() syntax. It also is the reason you see tango.io.Console.Console.Output.append (char[]). Your corrected code: ====================================================== import tango.io.Console; void main() { Cout("What is your name? ").flush; char[] name; if(Cin.readln(name)) { Cout("Hello ")(name).newline; } } ==================================================
Jun 06 2008
Mike Parker Wrote:SodiumFree wrote:Good Mike , and this goes too module test4; import tango.io.Console; void main(){ Cout("What is your name? ").flush; char[] name; Cin.readln(name); char[] lead = "Hello "; Cout(lead)(name).newline; }So i copy this code, pretty much straight from the book (page 139): module inputTest; import tango.io.Console; void main(){ Cout("What is your name? ").flush; auto name = Cin.readln; Cout("Hello ")(name).newline; } However when i try compiling, dmd spits out this error: C:\d.stuff\inputTest>dmd inputTest.d inputTest.d(6): function tango.io.Console.Console.Input.readln (char[],bool) does not match parameter types () inputTest.d(6): Error: expected 2 arguments, not 0 inputTest.d(7): function alias tango.io.Console.Console.Output.append (char[]) does not match parameter types (bool) inputTest.d(7): Error: expected 0 arguments, not 1 Any idea what's going on?Cin.readln (which is the method tango.io.Console.Console.Input.readln) expects at least one argument -- a string in which to store the input. You've given it nothing. The compiler reports this in the first error, then keeps on compiling. Second, 'name' is automatically inferred as a bool and not as a string as you seem to intend it to be. You'll see in the documentation that readln returns true if input is read and false if not. So the compiler sees you trying to pass a bool value in the call to Cout when it expects a string, resulting in the second error. A look at the source for tango.io.Console should make the error messages more clear. Console is a struct with the inner classes Input and Output. Cin is an instance of Console.Input. Hence the tango.io.Console.Console.Input.readln (char[],bool) in the error string. In Console.output, the append method is aliased to opCall. That's what allows the COut()() syntax. It also is the reason you see tango.io.Console.Console.Output.append (char[]). Your corrected code: ====================================================== import tango.io.Console; void main() { Cout("What is your name? ").flush; char[] name; if(Cin.readln(name)) { Cout("Hello ")(name).newline; } } ==================================================
Jun 06 2008
Thanks, both examples make the explanation a lot clearer. Rather strange that something like this has made it into the book though.
Jun 06 2008
"SodiumFree" <bob pistachios.com> wrote in message news:g2c3e2$2v9h$1 digitalmars.com...Thanks, both examples make the explanation a lot clearer. Rather strange that something like this has made it into the book though.It's probably because Tango is not complete, and has been in a constant state of flux for the past year and a half since it was announced. When that chapter of the book was written, that probably was the interface to Cin.readln.
Jun 06 2008
Jarrett Billingsley wrote:"SodiumFree" <bob pistachios.com> wrote in message news:g2c3e2$2v9h$1 digitalmars.com...I know it's in alpha, but I really wish the Tango devs (and Phobos, too) would put more thought into backwards compatibility. Even if it's just a deprecated function to forward to the new API, I'd rather it be there to allow old programs to compile. </complaining about something I didn't pay for or help with>Thanks, both examples make the explanation a lot clearer. Rather strange that something like this has made it into the book though.It's probably because Tango is not complete, and has been in a constant state of flux for the past year and a half since it was announced. When that chapter of the book was written, that probably was the interface to Cin.readln.
Jun 06 2008
"Jarrett Billingsley" wrote"SodiumFree" <bob pistachios.com> wrote in message news:g2c3e2$2v9h$1 digitalmars.com...I don't have a copy of the book, but I think it is just a book typo. According to this changeset: http://www.dsource.org/projects/tango/changeset/2094 readln always had the current interface since it was introduced. What the book should have done was used copyln (or get): void main(){ Cout("What is your name? ").flush; auto name = Cin.copyln; // or Cin.get Cout("Hello ")(name).newline; } -SteveThanks, both examples make the explanation a lot clearer. Rather strange that something like this has made it into the book though.It's probably because Tango is not complete, and has been in a constant state of flux for the past year and a half since it was announced. When that chapter of the book was written, that probably was the interface to Cin.readln.
Jun 09 2008