push_back to Multidimensional Vector

Mar 21, 2012 at 11:50pm
Hey guys I'm new here, hopefully ill be able to contribute in the future but I have a question at the moment. I'm programming a multidimensional vector and I'm wondering how I can push_back to only the first dimension of the array.

 
vector<vector<string, int> > censoredWords;

this is the array declaration.

1
2
3
4
while (ss >> bufferString[0])
	{
        Words.push_back(bufferString); //line a
	}


On line a this is where I want to push_back to the 1st dimension in the 2d array.
Mar 22, 2012 at 12:11am
If you want to add to the second dimension, use this and replace 0 with the index of the vector along the first dimension:

Words[0].push_back(bufferString);

If you want to add a whole new vector to the vector, your code looks correct.

The trick is that you shouldn't think of this as a "2-dimensional array." Just think of it as a vector of vectors.
Last edited on Mar 22, 2012 at 12:15am
Mar 22, 2012 at 12:25am
Thanks alot, I understand the concept its just the syntax :)
Topic archived. No new replies allowed.