On Monday, 7 December 2020 at 03:51:02 UTC, Paul Backus wrote:
On Monday, 7 December 2020 at 02:25:23 UTC, mw wrote:
onlineapp.d(8): Error: no [] operator overload for type CsvRecord!(int, cast(Malformed)1, string, dchar)

should `r`'s type be integer array? and how do I access each elelment of the row?

Thanks.

The docs [1] say that csvReader returns an input range, not an array. Input ranges don't support indexing, only iteration (e.g. with `foreach`). If you want an array, you will have to use `std.array.array` to create one.

[1] http://phobos.dpldocs.info/std.csv.csvReader.1.html

Thanks.

I saw the 1st example on this page:

https://dlang.org/phobos/std_csv.html

foreach (record; csvReader!(Tuple!(string, string, int))(text))
    {
        writefln("%s works as a %s and earns $%d per year",
                 record[0], record[1], record[2]);
    }

So my next question: given N, how do I create a Tuple!(double, double, ... n-double) type programmatically?




Reply via email to