August 09, 2015 Re: Dynamic array and foreach loop | ||||
---|---|---|---|---|
| ||||
Posted in reply to Binarydepth | On Sunday, 9 August 2015 at 19:10:01 UTC, Binarydepth wrote: > On Sunday, 9 August 2015 at 16:42:16 UTC, Jay Norwood wrote: > Oooh... I like how this works > > import std.stdio : writeln, readf; > void main() { > immutable a=5; > int[a] Arr; > int nim; > foreach(num, ref nem; Arr) { > readf(" %s", &nem); > } > foreach(num; Arr) { > writeln(num); > } > } you can also do something like this to accept blank separated input values on a single line. import std.stdio : writeln, readln; import std.string: split; import std.conv: to; import std.algorithm: each; void main() { double [] Arr; Arr = readln().split().to!(double[]); Arr.each!writeln(); } |
Copyright © 1999-2021 by the D Language Foundation