Vector of vectors

Hello to all,

I have a vector of strings and i want to put this vector of strings inside another vector, so I do:

std::vector<std::string> vect_aux; // my vector of strings
std::vector<std::vector> vect_mat; // my vector of vectors - this is give me error that is: type argument 2 invalid. I do not understand why. Can someone give me a tip?

One more thing, to put a vector inside another we have to do:
vect_mat[0] = vect_aux;

or there are other better ways?

Regards,
CMarco
You need to declare vector correctly:

std::vector<std::vector<std::string> > vect_mat;

You migth want to do something like this:
1
2
typedef std::vector<std::string> vect_aux_t;
std::vector<vect_aux_t> vect_mat;


One more thing, to put a vector inside another we have to do:
vect_mat[0] = vect_aux;
What's wrong with that?
Hi,

my IDE only accept if declared like:

std::vector<std::string> vect_aux; // my vector of strings
std::vector<std::vector<std::string> > vect_mat; // my vector of vectors

to put one inside another i was also thinking in:
vect_mat.push_back(vect_aux);

To search inside of my vector of vector I was thinking in a cycle for like:
for (size_t n = 0; n < vect_mat.size(); n++)
EV << '''' << vect_mat[n] << '"' << '\n';

bu this is not working, someone can advise me.

Regards,
CMarco
Hi,

the error of my cycle for, is because EV can not show me the output/content of the vect_mat because this is to big. Even cout do not work...

Regards,
CMarco
if vect_aux should be added then yes you need push_back(). Except you know beforehand the size of your vector. then you can use resize():

http://www.cplusplus.com/reference/stl/vector/resize/


The loop is not working since it's a two dimensional vector. So you need nested loops:
1
2
3
4
5
6
for (size_t n = 0; n < vect_mat.size(); n++)
{
for (size_t m = 0; m < vect_mat[n].size(); m++)
EV << '"' << vect_mat[n][m] << '"' << '\n'; // Note: '"' not ''''
}
}


Please use code tags: [code]Your code[/code]
See: http://www.cplusplus.com/articles/z13hAqkS/
Hi,

Thanks...
sorry, code tags will be use from now on.

Regards,
CMarco
Topic archived. No new replies allowed.