www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - strip() and formattedRead()

reply realhet <real_het hotmail.com> writes:
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?
Mar 21 2018
next sibling parent =?UTF-8?Q?Ali_=c3=87ehreli?= <acehreli yahoo.com> writes:
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
Mar 21 2018
prev sibling parent reply Adam D. Ruppe <destructionator gmail.com> writes:
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 = "xxxx".strip; formattedRead(s, ....)
Mar 21 2018
parent realhet <real_het hotmail.com> writes:
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 = "xxxx".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.
Mar 21 2018