D Programming Language Tutorial - Area of a Circle - Error: Undefined identifier toFloat -


I have just started learning. When I create this tutorial file:

(directly from the D site), I get these errors:

  circle.d | 24 | Error: template can not remove std.stdio.readln function by logic type! () (File), candidates are: | /usr/share/dmd/src/phobos/std/stdio.d | 2818 | Std.stdio.readln (s = string) (dchar terminator = '\ x0a') if (isSomeString! S) | /usr/share/dmd/src/phobos/std/stdio.d | 2851 | Std.stdio.readln (C) (Ref (C) buf, dchar terminator = '\ x0a') if (is Somacher! C & amp; (Aqua! C == C) & amp; is (C = = Enum )). /usr/share/dmd/src/phobos/std/stdio.d | 2858 | Std.stdio.readln (C, R) (Ref C [] Buff, R terminator) If (is Somachar! C & amp; is (ANQUA! C == C) & amp;; (C == enum) Amp; isBidirectionalRange! R & amp; is (typef (Terminator.fr == (dchar) .init))). Circle.d | 25 | Error: Float to undefined identifier. || === Build Failed: 5 Error (), 0 Warning (0 Minutes, 0 Seconds (Seconds)) === |  

Edit:

So I end up with this

:

  Import std.conv; Import std.stdio; Import std.string; Import std.math; Const real pi = std.math.PI; Zero main () {try {const char [] chRadius; Float R; Writef ("Enter Radius:"); ChRadius = chomp (readln ()); R = to! Floating chradius; Writefln ("Circle Area =% F", PI * R * R); } Hold (exception e) {writefln ("catch% s", e.ostustring ()); }}  

The build message is:

  === Create: Debug in a circle area (compiler: Digital Mars de Compiler) == = | Circle.d | 24 | Error: const expression can not modify chRadius. || === Build Failed: 1 Error (), 0 Warning (0 Minutes, 0 Seconds (Seconds)) === |  

Edit 2: Change const char [] to string , and everything works! Thanks! As mentioned, @ miken32 has been mentioned that the tutorial is very old - the given source will be needed. To be modified for the modern D compiler:

  1. Call
  2. without any discussion to read from stdin. You can use the File.readln to read the file handle, but in this situation just use chRadius = chomp (readln ())
  3. You can also use const (char) [] ) instead of < string char []
  4. Float instead of tofloat ! ! Float indicates that type float from the normal function to
>

Comments