473,699 Members | 2,461 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

std::vector in vector - LOOPING

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_ty pe i = 0; i < set_of_V.size() ; i++)
{
t_gesture::cons t_iterator v = set_of_V[i].begin();
while (v != set_of_V[i].end())
{
vector.push_bac k(*v);
v++;
}
vector.clear(); // doesn't clear values
vector.erase(ve ctor.begin(), vector.end()); // doesn't erase values
int a1 = static_cast<uns igned int>(vector.siz e()); // should be always the
same size!
}
// at the end of loop 'a1 = a1 * 5'
....

THX a lot
Jul 23 '05 #1
1 1672
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_ty pe i = 0; i < set_of_V.size() ; i++)
{
t_gesture::cons t_iterator v = set_of_V[i].begin();
What is t_gesture?
while (v != set_of_V[i].end())
{
vector.push_bac k(*v);
v++;
}
vector.clear(); // doesn't clear values
vector.erase(ve ctor.begin(), vector.end()); // doesn't erase values
int a1 = static_cast<uns igned int>(vector.siz e()); // 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_i terator i=set_of_V.begi n();i!=set_of_V .end();i++)
for(t_vec::cons t_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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

27
5957
by: Jason Heyes | last post by:
To my understanding, std::vector does not use reference counting to avoid the overhead of copying and initialisation. Where can I get a reference counted implementation of std::vector? Thanks.
18
2866
by: Janina Kramer | last post by:
hi ng, i'm working on a multiplayer game for a variable number of players and on the client side, i'm using a std::vector<CPlayer> to store informatik about the players. CPlayer is a class that contains another std::vector<CPosition>. Because one of the players is the client itself (and the size of the vector<CPlayer> doesn't change during a game), i thought i could store a std::vector<CPlayer>::iterator "localplayer" that points to the...
20
17817
by: Anonymous | last post by:
Is there a non-brute force method of doing this? transform() looked likely but had no predefined function object. std::vector<double> src; std::vector<int> dest; std::vector<double>::size_type size = src.size(); dest.reserve(size); for (std::vector<int>::size_type i = 0;
17
3348
by: Michael Hopkins | last post by:
Hi all I want to create a std::vector that goes from 1 to n instead of 0 to n-1. The only change this will have is in loops and when the vector returns positions of elements etc. I am calling this uovec at the moment (for Unit-Offset VECtor). I want the class to respond correctly to all usage of STL containers and algorithms so that it is a transparent replacement for std:vector. The options seems to be:
3
1748
by: Pelle Beckman | last post by:
Hi all, I have a few - beginners - questions: * Why can't I put object references in a std::vector, i.e std::vector<MyClass&> ? At least in doesnt work in gcc (mingw, win32) * What's the difference between passing member inits in the c-tor funtion from
8
5108
by: Ross A. Finlayson | last post by:
I'm trying to write some C code, but I want to use C++'s std::vector. Indeed, if the code is compiled as C++, I want the container to actually be std::vector, in this case of a collection of value types or std::vector<int>. So where I would use an int* and reallocate it from time to time in C, and randomly access it via , then I figure to copy the capacity and reserve methods, because I just need a growable array. I get to considering...
32
69678
by: zl2k | last post by:
hi, c++ user Suppose I constructed a large array and put it in the std::vector in a function and now I want to return it back to where the function is called. I can do like this: std::vector<int> fun(){ //build the vector v; return v; }
5
32563
by: atreya | last post by:
Hi, I'm trying to figure out if there are any differences between the implementation of resize(0) and clear() that a programmer using std::vector should be aware of! Could there be any advantage/disadvantage of using one over the other? I checked the VS7.1 implementation, in which I couldn't find any difference. Both of them are effectively calling erase(begin(), end()).
56
5782
by: Peter Olcott | last post by:
I am trying to refer to the same std::vector in a class by two different names, I tried a union, and I tried a reference, I can't seem to get the syntax right. Can anyone please help? Thanks
13
2955
by: jubelbrus | last post by:
Hi I'm trying to do the following. #include <vector> #include <boost/thread/mutex.hpp> #include <boost/shared_ptr.hpp> #include <boost/tuple/tuple.hpp> class {
0
9174
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9035
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8914
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8884
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7751
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6534
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3057
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2347
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2009
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.