T
T. Crane
Hi,
I'm struggling with how to initialize a vector<vector<double>>
object. I'm pulling data out of a file and storing it in the
vector<vector<double>> object. Because any given file will have a
large amount of data, that I read off using an ifstream object, I
don't want to use the push_back method because this grows the
vector<vector<double>> dynamically, and that will kill my execution
time. So, I want to reserve space first, using, of course the reserve
method. However, I'm not sure what the best way of doing this is.
Here's what I am thinking of doing (I don't even know if this will
work) but if there's a better way to do it, I'm all ears:
#include <vector>
int nColumns = 10;
int nRows = 15;
vector<vector<double>> myData;
myData.reserve(nRows);
for (int i;i<nRows;i++){
myData.reserve(nColumns);
}
thanks,
trevis
I'm struggling with how to initialize a vector<vector<double>>
object. I'm pulling data out of a file and storing it in the
vector<vector<double>> object. Because any given file will have a
large amount of data, that I read off using an ifstream object, I
don't want to use the push_back method because this grows the
vector<vector<double>> dynamically, and that will kill my execution
time. So, I want to reserve space first, using, of course the reserve
method. However, I'm not sure what the best way of doing this is.
Here's what I am thinking of doing (I don't even know if this will
work) but if there's a better way to do it, I'm all ears:
#include <vector>
int nColumns = 10;
int nRows = 15;
vector<vector<double>> myData;
myData.reserve(nRows);
for (int i;i<nRows;i++){
myData.reserve(nColumns);
}
thanks,
trevis