How to add elements to dynamic array of dynamic array

bearophile via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jun 7 10:04:35 PDT 2014


katuday:

> I am very new to D.

Welcome to D :-)


> 	alias the_row = string[];
> 	alias the_table = the_row[];

Here you are defining two types (and in D idiomatically types are 
written in CamelCase, so TheRow and TheTable).


> 	File inFile = File("account.txt", "r");

This is enough:

auto inFile = File("account.txt", "r");


> 	while (!inFile.eof())
> 	{
> 		string row_in = chomp(inFile.readln());

This should be better (untested):

foreach (rawLine; inFile.byLine) {
     auto row = rawLine.chomp.idup.split("\t");


> 		the_table ~= row_out; //Error: string[][] is not an lvalue

theTable is not a variable, it's a type, so you need to define it 
like this:

string[][] table;

Bye,
bearophile


More information about the Digitalmars-d-learn mailing list