J
Jessica
Hi,
I do not have a lot of experience with STL and I hope some of you
might be able to help me on this seemingly elementary question.
I have a vector of doubles (v1). I am trying to copy the values to
a 2D vector, of which every vector has the same length. I tried the
following but I get a "System.NullReferenceException" error when I ran
it.
cycle = 2;
n = 12;
vector< vector<double> >v2D;
v2D.reserve(cycle);
for (int i = 0; i < cycle; i++)
{
beginOffset = i * n;
endOffset = beginOffset + n;
v2D.reserve(n);
copy(v1.begin() + beginOffset, v1.begin() + endOffset,
v2D.begin());
}
Basically what I am doing is taking n numbers at a time iteratively,
and push them to a 2D vector of size 2-by-n. I also tried using
back_inserter in place of v2D.begin() but it didn't help. Am I
doing something wrong? Thanks.
Jessica
I do not have a lot of experience with STL and I hope some of you
might be able to help me on this seemingly elementary question.
I have a vector of doubles (v1). I am trying to copy the values to
a 2D vector, of which every vector has the same length. I tried the
following but I get a "System.NullReferenceException" error when I ran
it.
cycle = 2;
n = 12;
vector< vector<double> >v2D;
v2D.reserve(cycle);
for (int i = 0; i < cycle; i++)
{
beginOffset = i * n;
endOffset = beginOffset + n;
v2D.reserve(n);
copy(v1.begin() + beginOffset, v1.begin() + endOffset,
v2D.begin());
}
Basically what I am doing is taking n numbers at a time iteratively,
and push them to a 2D vector of size 2-by-n. I also tried using
back_inserter in place of v2D.begin() but it didn't help. Am I
doing something wrong? Thanks.
Jessica