I have an array:
const string ARRAY[][3] = {
{"Kolkata","Mumbai","218"},
{"Kolkata","New Delhi","316"},
...
{"Mumbai","Chennai","715"},
{"Chennai","Bangalore","516"},
};
This was a convenient way to store the entire table because I knew how many rows I had. However, in the future, the data needs to be read from a file, which can and will be edited by anyone.
I thought of creating a struct, something like:
typedef struct row {
string col1;
string col2;
string col3;
} row_t;
and then creating a vector<row_t>. Is this a good idea? Is there an easier way of doing this using an stl container? I also thought of creating a table large enough to last for a while (the number of rows does not change that often), but that does not feel right..
Thanks!
The most straightforward conversion would be to use an array in the struct:
Or you can use the
std::/std::tr1::/boost::arrayclass template:If you are going to use separate data members for each of the elements, as you show in your example, you should give them useful names and not just name them “col#”.