storing a vector in a vector

Hi C++ Forum,

I'm a relative newbie to C++ programming. I'm trying to store vectors in a vector. The only help I've seen on the forum gives the code for a matrix of values, ie a 2D array. However, what I want is a vector containing vectors as its elements.

Can anyone give me any ideas?

whiteboard cleaner says "thanks" :)
It is as simple as describing it. Have you tried it? Are you getting errors of any kind?
Thanks for the reply,

I wrote something like:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include "stdafx.h" 
#include<cstdio>
#include<cmath>
#include<iostream>
#include<vector>
using namespace std;


int main() {

 int B, K;
 const int N =2; 
 const int n = 5;
 double FINAL[n][N];

 for(int s=1; s<=n; s++)
	{
 for(int i=0; i<=N; i++)
			{
FINAL[s][i]=B; 
 cout << "(s=" << s << ") (i=" << i << ")" << endl;
            } //end 2nd loop
   	}//end 1st loop
 cin >> K;
return 0;
}

This works: no errors. But I think it's setting the results to a matrix not a vector.

Now I'm wondering if it matters....

I need to plug the final result into Mathematica to get a plot. I figured mathematica would have preferred a single vector (FINAL) of solutions.

confused whiteboard cleaner
Well, you are not using a vector anywhere, so you really can't expect a vector, right? A vector looks like this:

1
2
3
std::vector<int> vectorOfInts;
//As an exercise you declare a vector of vector of ints.
<Try it out> vectorOfVectorOfInts;
So is it that what I'm declaring is an nxN array? Will try the "vector<int>" command...
Yes, that's a simple nxN array, and not a STL vector.
Okay,

I got something working. (even though, I was told to just stick to an array type). Thanks a lot webJose! :)
Topic archived. No new replies allowed.