so what i'm trying to get my head around it say i have a vector of vectors containing some unsigned chars and i want to copy a certain vector to another vector as follows.

std::vector< std::vector< unsigned char > > foo;
std::vector < unsigned char > bar;

for (int x = 0; x < foo.size(); x++)
{
    // do stuff
    if (x == 3)
    {
        bar.push_back(&foo[x]);
    }
}

How can i go about doing this?

Thanks in advance.

Recommended Answers

All 2 Replies

How about:

bar = foo[3];

?

so what i'm trying to get my head around it say i have a vector of vectors containing some unsigned chars and i want to copy a certain vector to another vector as follows.
...
How can i go about doing this?

Do you want to have a copy of the original vector or do you want the modifications to either version to affect the other? I'll assume the former.

std::vector< std::vector< int > > vvi;
std::vector< int > vi;

//...
std::copy (vvi[3].begin (), vvi[3].end (), std::back_inserter(vi));

std::copy will copy all elements between the first two iterators into the location starting at the third iterator. In this case, to append to whatever contents are in the destination already, you can use a std::back_inserter .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.