Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

changin name of container by iteration 1

Status
Not open for further replies.

chineerat

Technical User
Oct 12, 2003
42
TT
Hello there!
this question might be a LONG SHOT but i'll ask anyways.

lets say i have the structures
struct matrix_1 {
string number_1;
string row_1;
string col_1;
}data_1;

struct matrix_2 {
string number_2;
string row_2;
string col_2;
}data_2;


notice the only difference between them are "1" and "2"
i want to store values in both structures, firstly in data_1 and then data_2.
is there anyway by iteration i can store my values into data_n , where n= 1 and then iterate n so afterwards i can store values into data_2

eg...

while (){
//code to store value into data_n.number_n
//code to store value into data_n.col_n
//code to store value into data_n.row_n
n++ ;
}

or do i have to do it the long way?
that is,
store into data_1 and den write over the same code for data_2?

thanks in advance...
 
You should define only one struct without the _1 or _2. Then, you create an instance of that struct every time you need it. So you can create 2 different instances if you need two different instances, or you can create a vector/array of the matrix structs if you want a bunch of them. In your example n would be the index of the vector/array.
 
WO, Thanks man.
dats a pretty nifty idea.

but it comes down to me storing a vector of type 'struct' into another vector.
dats REALLLLLLLLLLY cool
thanks a million.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top