At last i got this 2D vector of struct syntax in C++.

Kindly help to visualize how i will make the database (like an excel worksheet) using this declaration i have just found out.

Refer to this site where i got the declarations below:
http://cboard.cprogramming.com/cplusplus-programming/145547-2d-vector-struct-1d-pointer.html

struct myStruct{ int iA; double dB; }; //declaring a struct -- i would like my struct to contain a mixture of variables of different data types

vector< vector<myStruct> > data2D; //declaring a 2D vector to contain the struct variables

data2D.push_back(vector <myStruct>()); // initializing 2D vector using struct variables in a 1D vector

myStruct row; row.iA=1; row.dB=2.3; // initializing the struct variables - how to do this at runtime ??

data2D[0].push_back(row);// to copy contents of struct object (row) to 2D
vector ?

data2D.push_back(vector <myStruct>());// a 1D constructor ???

row.iA=4; row.dB=5.6; //why continue initialising the struct variables here ??

data2D[1].push_back(row);// I think first row of vector is being initialized ?






I would like my struct to contain the following and which shall be field/ column headings.

The user will input specific data row-wise.
This he will determine at runtime by answering a question "How many records do you want to enter information ?"... then the counter should loop through the row as user enters information guided by the column headings upto column 15.

The counter will then jump to row 2 if he had selected to create two records and so on.

My struct contains:

struct LandRecord
{
//i would like these to be the column headings which should althrough occupy the first row of the database/ vector.

int lr_unit_number;
std::string name_of_proprietor;
int national_id_cardnumber;
std::string address_of_proprietor;
char pin_number_of_proprietor ;
char date_of_acquisition ;
std::string date_of_issue_of_titledeed;
std::string category;
std::string type_of_ownership;
char county_located ;
char district_located ;
char division_located ;
char location_located ;
char sublocation_located ;
char village_located ;
}

How will i be able to push_back into the 2D vector to enter the user specific information into the 15-columns table ?

Suggestion on a different approach is welcome. I want to enter the data to a textfile, then use a function to read and display the whole textfile database, another function to check for a specific data in the textfile and return whether such a string exists and if so, how many times.

I am not conversant with lambdas thus i have taken much time to understand when i get such a contribution, kindly use the student-friendly common implementation C++ syntax.

I am a student and writing a college project.



Last edited on
Kindly help to visualize how i will make the database

Kindly use code tags - http://www.cplusplus.com/articles/jEywvCM9/
Topic archived. No new replies allowed.