473,405 Members | 2,210 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Vector element manipulation

2
Hi,

First of all I am a beginner in STL. Please apologies for any stupid mistakes!

I have a created vector<double> xpos[4] which stores double numbers. In my vector xpos[0], xpos[1], xpos[2], xpos[3] have different sizes. I would like to call and compare xpos elements and ask for each has to have at least one element at the same instant. Let me explain the following:

Expand|Select|Wrap|Line Numbers
  1. vector<double> xpos[4];
  2. vector<double> newxpos[4];
  3.  
  4. for(int i=0; i<max_event; i++){
  5.      for(int roc=0; roc<4; roc++){
  6.           xpos[roc].push_back[i];
  7.      {
  8. }
I can use the xpos[0] because it has the maximum size!
Expand|Select|Wrap|Line Numbers
  1. for(int j=0; j<4; j++){
  2.      for(int k=0; k < xpos[0].size(); k++) {                                               
  3.           if(xpos[1][k] != 0. && xpos[2][k] != 0. && xpos[3][k] != 0.){
  4.                  newxpos[j].(?)
  5.           }
  6.      } 
  7.  
? ==> I do not know how to call the elements of xpos[all] when all matches?

Thanks.
Jun 7 '07 #1
3 1537
Silent1Mezzo
208 100+
Hi,

First of all I am a beginner in STL. Please apologies for any stupid mistakes!

I have a created vector<double> xpos[4] which stores double numbers. In my vector xpos[0], xpos[1], xpos[2], xpos[3] have different sizes. I would like to call and compare xpos elements and ask for each has to have at least one element at the same instant. Let me explain the following:

Expand|Select|Wrap|Line Numbers
  1. vector<double> xpos[4];
  2. vector<double> newxpos[4];
  3.  
  4. for(int i=0; i<max_event; i++){
  5.      for(int roc=0; roc<4; roc++){
  6.           xpos[roc].push_back[i];
  7.      {
  8. }
I can use the xpos[0] because it has the maximum size!
Expand|Select|Wrap|Line Numbers
  1. for(int j=0; j<4; j++){
  2.      for(int k=0; k < xpos[0].size(); k++) {                                               
  3.           if(xpos[1][k] != 0. && xpos[2][k] != 0. && xpos[3][k] != 0.){
  4.                  newxpos[j].(?)
  5.           }
  6.      } 
? ==> I do not know how to call the elements of xpos[all] when all matches?

Thanks.
First Welcome to these forums.
Second generally its nice to put all code between [ CODE] [/code] brackets
Thirdly my memory's a little foggy on vectors but I don't believe there is a way to call all of the elements....You could just do it manually and save it into the new vector (if they all match then using only one of them will produce the same results).
Jun 7 '07 #2
AdrianH
1,251 Expert 1GB
Hi,

First of all I am a beginner in STL. Please apologies for any stupid mistakes!
No problem.

Right at the moment, I'm having trouble understanding what you are attempting. can you explain in words what it is you are trying to do?

Thanks,


Adrian
Jun 7 '07 #3
kistan
2
I have this vector xpos[4]. Each member (e.g. xpos[1]) in the vector has different sizes. I would like match them according the requirement that I need which is basically one element per each member. How can I access all these vector members and match them and after push_back them into a new vector.

Please look at the code I have in my first post.

Thanks.
Jun 7 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

34
by: Adam Hartshorne | last post by:
Hi All, I have the following problem, and I would be extremely grateful if somebody would be kind enough to suggest an efficient solution to it. I create an instance of a Class A, and...
6
by: Roman Töngi | last post by:
I want to change a vector in a function. I pass a pointer of it to the function and append an item. Then I want to print the first item in the vector. It doesn't work. Can anyone help me? Thanks...
5
by: laniik | last post by:
Hi. I have a STL vector of some relativly complicated objects I was wondering if there was a good way to remove objects from the middle of the vector. Currently the only way I know how to...
10
by: eiji | last post by:
Hi folks, I have a problem compiling this under VC6! Maybe someone has some minutes to look at this: template<class T> class Compare { public: Compare(){}; virtual ~Compare(){};
1
by: razilon | last post by:
Hi, I've written a managed class that makes use of stl vectors of a few unmanaged structs for data handling/manipulation, but I'm getting a few very strange errors. I get an "Unhandled...
0
by: razilon | last post by:
Hi, I've written a managed class that makes use of stl vectors of a few unmanaged structs for data handling/manipulation, but I'm getting a few very strange errors. I get an "Unhandled...
3
by: eriwik | last post by:
I use the following structure to store filenames for one or more "sets" grouped together by a number: map<int, map<string> > fileSets; As arguments to the constructor I send a...
4
by: arnuld | last post by:
i wrote a programme to create a vector of 5 elements (0 to 4), here is the code & output: #include <iostream> #include <vector> int main() { std::vector<intivec; // dynamically create a...
3
by: PolkaHead | last post by:
I was wondering if there's a way to traverse a two-dimensional vector (vector of vectors) with a nested for_each call. The code included traverses the "outer" vector with a for_each, than it...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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...
0
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...

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.