By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,159 Members | 980 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,159 IT Pros & Developers. It's quick & easy.

std::vector in vector - LOOPING

P: n/a
Hi,

Could someone know what is wrong with my code.
First of all what I'm trying to do.
I have (as can be seen) declared typedef's of vector STL.
I want each value in vector which is part of t_set of vectors to be part of
new vector
for future use.
But I want to reuse that variable vector by clearing or erasing the values
form it.

This is my part of code which ...

in skalar.h
....
typedef vector<double> t_vec;
typedef vector<t_vec> t_set;
....
in skalar.cpp
....
t_vec vector;
....
for (t_set::size_type i = 0; i < set_of_V.size(); i++)
{
t_gesture::const_iterator v = set_of_V[i].begin();
while (v != set_of_V[i].end())
{
vector.push_back(*v);
v++;
}
vector.clear(); // doesn't clear values
vector.erase(vector.begin(), vector.end()); // doesn't erase values
int a1 = static_cast<unsigned int>(vector.size()); // should be always the
same size!
}
// at the end of loop 'a1 = a1 * 5'
....

THX a lot
Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
robk wrote:
Hi,

Could someone know what is wrong with my code.
First of all what I'm trying to do.
I have (as can be seen) declared typedef's of vector STL.
I want each value in vector which is part of t_set of vectors to be part of
new vector
for future use.
But I want to reuse that variable vector by clearing or erasing the values
form it.
You must choose: Either you store the value or you delete them.

This is my part of code which ...

in skalar.h
...
typedef vector<double> t_vec;
typedef vector<t_vec> t_set;
...
in skalar.cpp
...
t_vec vector;
Why do you call it "vector" which is an already used name here? (See you
typedef.)
...
for (t_set::size_type i = 0; i < set_of_V.size(); i++)
{
t_gesture::const_iterator v = set_of_V[i].begin();
What is t_gesture?
while (v != set_of_V[i].end())
{
vector.push_back(*v);
v++;
}
vector.clear(); // doesn't clear values
vector.erase(vector.begin(), vector.end()); // doesn't erase values
int a1 = static_cast<unsigned int>(vector.size()); // should be always the
same size!
}
// at the end of loop 'a1 = a1 * 5'
...
Have you tried something like the follwoing:
// Assuming "t_set set_of_V" and "t_vec TheVector" are defined
// elsewhere...
for (t_set::const_iterator i=set_of_V.begin();i!=set_of_V.end();i++)
for(t_vec::const_iterator j=i->begin();j!=i->end();j++)
TheVector.push_back(*j); // Assuming you want to store the values...

THX a lot


Regards,
Peter Jansson
http://www.jansson.net/

Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.