473,661 Members | 2,449 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 7168
m_*********@hot mail.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.beg in() + 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_*********@ho tmail.comschrie b im Newsbeitrag
news:11******** **************@ q16g2000cwq.goo glegroups.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_*********@hot mail.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_*********@hot mail.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
2132
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 generator and do a or any other kind of slice it reads all the values up to 100 also. I know a lot of generators have to do all previous parts before they can do the next part but it would be a nice optimization that can start at any index to...
10
3681
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. Andrew dalke@dalkescientific.com
2
5500
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 think, question about index (ie. position of objext in the map) of object 'iter' iterator points to, makes sense.
29
3960
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 case: class A {
6
3774
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; strings.push_back("abc"); strings.push_back("xyz"); strings.push_back("lmnop");
13
13395
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 better than index? For me (until now) iterators are very strangely objects because they are useless for me. But since most of members of containers use iterators, I am stumped.
6
2236
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 the "next" or "previous" entry in the array, but the keys are strings, instead of numerical indeces. thanks for your help.
14
22557
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 first occurence. I want to know the positions of both "1234" thanks
2
9824
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 the loop to iterate through using indexes instead of iterators, I just need the index for a little debug output, the rest of the code in the loop uses the iterator. thanks.
0
8343
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8633
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
7364
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
6185
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...
0
5653
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4346
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2762
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
1986
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1743
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.