Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old August 10th, 2006, 11:55 AM
m_schellens@hotmail.com
Guest
 
Posts: n/a
Default 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

  #2  
Old August 10th, 2006, 12:25 PM
Thomas Tutone
Guest
 
Posts: n/a
Default Re: index to iterator

m_schellens@hotmail.com wrote:
Quote:
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)
Quote:
{
if( (*yV)[ i] <= 0.0)
I think you mean:

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

Best regards,

Tom

  #3  
Old August 10th, 2006, 12:25 PM
Gernot Frisch
Guest
 
Posts: n/a
Default Re: index to iterator


<m_schellens@hotmail.comschrieb im Newsbeitrag
news:1155207729.680103.325640@q16g2000cwq.googlegr oups.com...
Quote:
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


  #4  
Old August 10th, 2006, 12:25 PM
Thorsten Kiefer
Guest
 
Posts: n/a
Default Re: index to iterator

m_schellens@hotmail.com wrote:
Quote:
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);
Quote:
xV->erase( ***what? ***); // want to earse xV[i]
xV->erase(xV->begin() + i);
Quote:
}
}
>
>
I know I could iterate through an iterator.
But to much typing for xV then.
>
Thanks,
Marc
  #5  
Old August 10th, 2006, 12:25 PM
m_schellens@hotmail.com
Guest
 
Posts: n/a
Default Re: index to iterator

Thank you all!

Thomas Tutone wrote:
Quote:
m_schellens@hotmail.com wrote:
Quote:
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

 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles