954,480 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Vector with Multiple Memebers

Does anyone know if this is possible?

//in header
struct Output
{
double *var1;
double *var2;
double *var3;
}

//in main
std::vector output(512);

and then be able to populate each member of the Output struct in the "output" vector?

Something like: ----------------------------

for (i = 0; i < 512; i++)
{
output->var1[i].push_back(value1);
output->var2[i].push_back(value2);
output->var3[i].push_back(value3);
}

-------------------------------------------

If so, what is the actual syntax (since this does not work).

Thanks!

-H

hfaucette
Newbie Poster
3 posts since Jul 2005
Reputation Points: 10
Solved Threads: 0
 
for(int i = 0; i < 512; i++)
    {
        output[i].var1 = (double *)i;
        output[i].var2 = (double *)i;
        output[i].var3 = (double *)i;    
    }

shuld populate it.

zyruz
Junior Poster in Training
60 posts since Jun 2005
Reputation Points: 10
Solved Threads: 5
 

Thank you zyruz!

One more question. How would I populate?

output[i].var1[i].push_back(double value); ??

Regards,

-H

hfaucette
Newbie Poster
3 posts since Jul 2005
Reputation Points: 10
Solved Threads: 0
 

if you are trying wath I think you are you need to change

struct Output
{
double *var1;
double *var2;
double *var3;
}

to

struct Output
{
std::vector<double> var1;
std::vector<double> var2;
std::vector<double> var3;
}

then can you use

output[i].var1[i].push_back(double_value);

but why not just use a vector in a vector:
std::vector< std::vector > var1; ?

zyruz
Junior Poster in Training
60 posts since Jun 2005
Reputation Points: 10
Solved Threads: 5
 

Okay. Thank you for the brain dump.

hfaucette
Newbie Poster
3 posts since Jul 2005
Reputation Points: 10
Solved Threads: 0
 

How would you handle a structure of mixed types then?

bumsfeld
Nearly a Posting Virtuoso
1,445 posts since Jul 2005
Reputation Points: 404
Solved Threads: 184
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You