C++ help!

Associate
Joined
28 Jun 2005
Posts
997
Location
London
Hi all,
I'm a c++ programming noob. Got a question.

I'm trying to store int values into a vector, then putting the int vector into another vector.
(does that makes sense?)
So i'd have the main vector, and at each element it will have a vector of ints.

I think i've saved these vectors, but i'm not sure how to access them - i've looked online and not found anything.

So, yeah. Just wondering how to cout the contents of a vector within a vector :confused:

Thanks!
 
Hi guys,
Thank you v.much for your replies.. I'm still not entirely getting it >.<

So... sorry to be a noob but:

"vector<vector<int> > vvi; // makes a vector of ints inside the vector
vector<int> vi1, vi2; // makes 2 more vectors, vi1 and vi2?

vi1.push_back(3); // puts 3 into vi1
vvi.push_back(vi1); // update/puts vi1 into vvi?

vi2.push_back(4); // puts 4 into vi2
vi2.push_back(5); // puts 5 into vi2
vvi.push_back(vi2);" // updates/puts vi2 into vvi?

Is there a way to make it dynamic? (i'm not sure if that is the correct term)
If data was entered...
1 2 - in one vector
3 4 - in another vector
So each line is a new vector of ints.. would it be possible to do that?

Thanks again for your time :)
 
I mean dynamic in the sense of:
without declaring the vectors at the top, would it be possible for it to add a vector of ints from an input?
So if the input was:
1 2
3 4
5 6
So for each line of input it would create a new vector of ints inside the main vector? I'm just wondering if it would be possible to do that? I'm not sure how it would work, and can't seem to find anything about it online or in any c++ books i have.

Thanks for the typedef tip!
 
Back
Top Bottom