std::vector in vector - LOOPING

R

robk

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.begin();
while (v != set_of_V.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
 
P

Peter Jansson

robk said:
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.begin();


What is t_gesture?
while (v != set_of_V.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/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top