Re: strip() and formattedRead()

2018-03-21 Thread realhet via Digitalmars-d-learn

On Wednesday, 21 March 2018 at 18:50:18 UTC, Adam D. Ruppe wrote:

On Wednesday, 21 March 2018 at 18:44:12 UTC, realhet wrote:
Compiling this I get an error: "formattedRead: cannot deduce 
arguments from (string, string, float, float, float)"


What compiler version are you using? The newest versions allow 
this code, though the old ones require an intermediate variable 
to satisfy the `ref` requirement on formattedRead (it will want 
to update that variable to advance it past the characters it 
read).


so either update your version, or just give an and use an 
intermediate:


string s = "".strip;
formattedRead(s, )


Thank both of You! You guys are super helpful. (I'm learning from 
Ali's book and after these instant answers I was like: "I'm not 
worthy" :D)


So I had v2077.1 previously, now I've installed 2079.0 and it all 
works great.





Re: strip() and formattedRead()

2018-03-21 Thread Adam D. Ruppe via Digitalmars-d-learn

On Wednesday, 21 March 2018 at 18:44:12 UTC, realhet wrote:
Compiling this I get an error: "formattedRead: cannot deduce 
arguments from (string, string, float, float, float)"


What compiler version are you using? The newest versions allow 
this code, though the old ones require an intermediate variable 
to satisfy the `ref` requirement on formattedRead (it will want 
to update that variable to advance it past the characters it 
read).


so either update your version, or just give an and use an 
intermediate:


string s = "".strip;
formattedRead(s, )


Re: strip() and formattedRead()

2018-03-21 Thread Ali Çehreli via Digitalmars-d-learn

On 03/21/2018 11:44 AM, realhet wrote:

   float x,y,z;
   if(formattedRead("    vertex -5.1 2.4 3.666".strip, "vertex %f %f 
%f", x, y, z)){

     writefln("v(%f, %f, %f)", x, y, z);
   }


formattedRead wants to modify the source, so it takes it by reference, 
which rvalues cannot be passed for. Make the source an lvalue (i.e. a 
proper variable):


  auto source = "vertex -5.1 2.4 3.666".strip;
  if(formattedRead(source, "vertex %f %f %f", x, y, z)){

Ali


strip() and formattedRead()

2018-03-21 Thread realhet via Digitalmars-d-learn

Hi,

I just got this problem and since an hour can't find answer to it.

  float x,y,z;
  if(formattedRead("vertex -5.1 2.4 3.666".strip, "vertex %f 
%f %f", x, y, z)){

writefln("v(%f, %f, %f)", x, y, z);
  }

Compiling this I get an error: "formattedRead: cannot deduce 
arguments from (string, string, float, float, float)"


When I don't use .strip(), just a string literal or a string 
variable it works good.


(It fails also when I'm using UFCS)

What did I do wrong?