how to access record[0] of a csv row? Error: no [] operator overload for type CsvRecord!(int, cast(Malformed)1, string, dchar)

mw mingwu at gmail.com
Mon Dec 7 02:25:23 UTC 2020


Hi,

I'm trying this code: i.e. print out the 1st element of each row

https://run.dlang.io/is/pG921a

void main()
{
     import std.csv;
     import std.stdio: write, writeln, writef, writefln;
     import std.algorithm.comparison : equal;
     string text = "76,26,22";
     auto records = text.csvReader!int;
     foreach(r; records) {writeln(r[0]);}   // line 8
     assert(records.equal!equal([
         [76, 26, 22],
     ]));
}


but I got a compile error:

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.



More information about the Digitalmars-d-learn mailing list