473,320 Members | 2,098 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,320 software developers and data experts.

index to iterator

How can I get from a vector index the iterator?

typedef std::vector< doubleTdoubleV;

doubleV xV;
doubleV yV;

// fill xV and yV with values (they have the same size)
....
for( SizeT i=0; i<yV->size(); ++i)
{
if( (*yV)[ i] <= 0.0)
{
yV->erase( ***what? ***); // want to erase yV[i]
xV->erase( ***what? ***); // want to earse xV[i]
}
}
I know I could iterate through an iterator.
But to much typing for xV then.

Thanks,
Marc

Aug 10 '06 #1
4 7150
m_*********@hotmail.com wrote:
How can I get from a vector index the iterator?

typedef std::vector< doubleTdoubleV;

doubleV xV;
doubleV yV;

// fill xV and yV with values (they have the same size)
...
for( SizeT i=0; i<yV->size(); ++i)
I think you mean:

for (doubleV::size_type i = 0; i<yV.size(); ++i)
{
if( (*yV)[ i] <= 0.0)
I think you mean:

if (yV[i]<=0.0)
{
yV->erase( ***what? ***); // want to erase yV[i]
yV.erase(yV.begin() + i);
xV->erase( ***what? ***); // want to earse xV[i]
}
}
I know I could iterate through an iterator.
Yes, that would make this easier and clearer.
But to much typing for xV then.
I don't understand what you mean.

Best regards,

Tom

Aug 10 '06 #2

<m_*********@hotmail.comschrieb im Newsbeitrag
news:11**********************@q16g2000cwq.googlegr oups.com...
How can I get from a vector index the iterator?

typedef std::vector< doubleTdoubleV;

doubleV xV;
doubleV yV;

// fill xV and yV with values (they have the same size)
...
for( SizeT i=0; i<yV->size(); ++i)
{
if( (*yV)[ i] <= 0.0)
{
yV->erase( ***what? ***); // want to erase yV[i]
xV->erase( ***what? ***); // want to earse xV[i]

(yV->begin() + i) // gives a forward iterator, increased by 'i'
elements.

See also std::advance
Aug 10 '06 #3
m_*********@hotmail.com wrote:
How can I get from a vector index the iterator?

typedef std::vector< doubleTdoubleV;

doubleV xV;
doubleV yV;

// fill xV and yV with values (they have the same size)
...
for( SizeT i=0; i<yV->size(); ++i)
{
if( (*yV)[ i] <= 0.0)
{
yV->erase( ***what? ***); // want to erase yV[i]
yV->erase(yV->begin() + i);
xV->erase( ***what? ***); // want to earse xV[i]
xV->erase(xV->begin() + i);
}
}
I know I could iterate through an iterator.
But to much typing for xV then.

Thanks,
Marc
Aug 10 '06 #4
Thank you all!

Thomas Tutone wrote:
m_*********@hotmail.com wrote:
How can I get from a vector index the iterator?

typedef std::vector< doubleTdoubleV;

doubleV xV;
doubleV yV;
I actually meant:

doubleV* xV;
doubleV* yV;
Marc

Aug 10 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: kosh | last post by:
I was wondering if there is or there could be some way to pass a generator an optional starting index so that if it supported that slicing could be made more efficient. Right now if you do use a...
10
by: Andrew Dalke | last post by:
Is there an author index for the new version of the Python cookbook? As a contributor I got my comp version delivered today and my ego wanted some gratification. I couldn't find my entries. ...
2
by: Maciej Kwapulinski | last post by:
hallo. This is my question: let's assume a map like: map< string, my_object > str_map; map< string, my_object >::iterator iter = str_map.find("hallo"); map is an sorted container, so I...
29
by: Hagen | last post by:
Hello, in a recent thread "speed of vector vs array" I read about the problem of the slow acces by addressing vector elements by indexing, unfortunately I see no workaround in my case. My...
6
by: Joe | last post by:
I have a: vector<string> which contains a few dozen elements. I want to find the index of the element containing a certain string. for example: vector<string> strings;...
13
by: Chameleon | last post by:
I am programming in C++ for 4 years, so I am not a newbie but I am not a very experienced programmer on standard C++ libary. My question is this: Can you tell me one case which an iterator is...
6
by: routeslip | last post by:
I'm refering to an entry in an array by it's string key, as in foo. Is there a way to get the numeric index of that array without iterating through the entire array? What I need to do is find...
14
by: micklee74 | last post by:
hi say i have string like this astring = 'abcd efgd 1234 fsdf gfds abcde 1234' if i want to find which postion is 1234, how can i achieve this...? i want to use index() but it only give me the...
2
by: Christopher | last post by:
Seems odd, but I was wondering if I am in the middle of iterating through a vector, is there a way to calc which index I am currently on? something like: it - vec.begin()? I don't want to change...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.