On Tuesday, 9 January 2018 at 17:00:05 UTC, thedeemon wrote:
On Tuesday, 9 January 2018 at 13:49:41 UTC, Vino wrote:
Hi All,
It is possible to store struct in a array ans use the same in
csvReader
Sure, you can just pass the type of your struct to csvReader:
struct Layout { string name; int value; double other; }
auto readArrayOfStructs(string fname) {
Array!Layout res;
foreach(record; fname.readText.csvReader!Layout('\t')) {
res ~= record;
}
return res;
}
Hi Deemon,
Thank you, and sorry for the confusion, the requirement is as
below
auto reader(T) (Array!T T1s, T fname) {
auto uFile = File(fName, "r");
foreach (record;
uFile.byLineCopy().joiner("\n").csvReader!(Tuple!T1s)) // receive
the type and fetch the record
writeln(record);
}
void main () {
auto fName =
"C:\\Users\\bheev1\\Desktop\\Current\\Script\\Others\\Table1.csv";
struct T1 { string Name; string Country; int Age; }
Array!T1 T1s;
reader(fName, T1s); // pass the array Type as a function parameter
}
From,
Vino.B