retrieving data from a file stream is as simple as
Code:
int i;
myfile >> i;
Although you really should perform error checking in case the data retrieved from the file is of the wrong type. (If this happens, the stream will fail/set failbit, and you'll need code to handle that)
you can also use
Code:
string s;
getline(myfile, s);
This will store it as plain text, and you'll need an extra step to parse the string to ints/floats. This is the long-winded way
Code:
Not sure if how to declare a vector of vectors
a vector of vectors is declared the same way as a vector of any other type.
Code:
vector< vector<int> >
or, if that looks ugly to you, use a typedef,
Code:
typedef vector< vector<int> > vec2D;
you could add/retrieve elements of your "2D" vector like this,
Code:
#include <vector>
#include <iostream>
using namespace std;
typedef vector< vector<int> > vec2D;
int main()
{
vec2D myData;
vector<int> vec;
vec.push_back(1);
myData.push_back(vec);
myData.at(0).push_back(2);
cout << myData.at(0).at(0) << " "
<< myData.at(0).at(1);
cin.get();
}
This is a bit of an ugly example since it uses "magic" numbers to access the elements, you're better off using iterators for reading the contents, but I hope this gives you the basic idea.