Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

unable to delete the value from a vector.

56 views
Skip to first unread message

K' Dash

unread,
Nov 23, 2014, 6:22:24 AM11/23/14
to
void GUID_LMS_application::RemoveEntry (GUID_address GUIDaddress)
{
Entry entry;

for (std::vector<Entry>::iteratori=m_listentry.begin();i!=m_listentry.end ();i++)
{

if (GUIDaddress== entry.GetGUIDaddress( ))
{
//std::cout<<"AAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n";

m_listentry.erase (i);
break;
}
}
}


dear all i want to delete the entry from a vector. but this piece of code is not working. The if condition is not succesful but my vecoter hold the entry. please help me

Jorgen Grahn

unread,
Nov 23, 2014, 6:57:15 AM11/23/14
to
On Sun, 2014-11-23, K' Dash wrote:
...
> Entry entry;
...
> if (GUIDaddress== entry.GetGUIDaddress( ))
...
> dear all i want to delete the entry from a vector. but
> this piece of code is not working. The if condition is not succesful but
> my vecoter hold the entry. please help me

Besides a lot of other problems which seem to come from bad copy &
paste, you never initialize 'entry'.

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .

JiiPee

unread,
Nov 23, 2014, 7:03:44 AM11/23/14
to
You create an entry variable but you do not fill it with anything... so
it's an empty object and then you use it in if condition, or is it
empty? Also you are looping i but you do not seem to use it in anyway in
the if-condition.

not sure, but I guess something like:

if (GUIDaddress== i->GetGUIDaddress( ))


bartekltg

unread,
Nov 23, 2014, 8:56:20 AM11/23/14
to
On 23.11.2014 12:22, K' Dash wrote:
> void GUID_LMS_application::RemoveEntry (GUID_address GUIDaddress) {
> Entry entry;
>
> for
> (std::vector<Entry>::iteratori=m_listentry.begin();i!=m_listentry.end
> ();i++) { if (GUIDaddress== entry.GetGUIDaddress( )) {
> //std::cout<<"AAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n";
>
> m_listentry.erase (i); break; } } }

WTF?

>
> dear all i want to delete the entry from a vector. but this piece of
> code is not working. The if condition is not succesful but my vecoter
> hold the entry. please help me

Where is the 'i' in the condition?
If the condition is meet, you just erase the first element.


Also, be careful:
http://en.cppreference.com/w/cpp/container/vector/erase
"Invalidates iterators and references at or after the point of
the erase, including the end() iterator. "

Bonus
http://en.wikipedia.org/wiki/Erase-remove_idiom

brt



JiiPee

unread,
Nov 23, 2014, 9:14:05 AM11/23/14
to
But he breaks the loop after erase, so I guess its fine.

K' Dash

unread,
Nov 23, 2014, 11:59:25 AM11/23/14
to
can you guys give me your email address so I can share you my files. not more just 2 files.

JiiPee

unread,
Nov 23, 2014, 12:59:41 PM11/23/14
to
On 23/11/2014 16:59, K' Dash wrote:
> can you guys give me your email address so I can share you my files. not more just 2 files.

donno all the code, but gussing: try this, does it work:

void GUID_LMS_application::RemoveEntry (GUID_address GUIDaddress)
{

for (std::vector<Entry>::iterator i=m_listentry.begin();i!=m_listentry.end ();i++)
{

if (GUIDaddress == i->GetGUIDaddress())
{
//std::cout<<"AAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n";

m_listentry.erase(i);
break;
}
}
}

what it says now (hope i did not leave errors)?


K' Dash

unread,
Nov 23, 2014, 1:18:38 PM11/23/14
to
not working. :(

my vector contains the two values

03-0a-0c:01:00:02:00:00:00:00:00:01 102.102.102.102
03-0a-0c:01:00:02:00:00:00:00:00:02 102.102.102.102
03-0a-0c:01:00:02:00:00:00:00:00:03 102.102.102.102
03-0a-0c:01:00:02:00:00:00:00:00:04 102.102.102.102
03-0a-0c:01:00:02:00:00:00:00:00:05 102.102.102.102==> according to code this entry need to delete.
03-0a-0c:01:00:02:00:00:00:00:00:06 102.102.102.102
03-0a-0c:01:00:02:00:00:00:00:00:07 102.102.102.102
03-0a-0c:01:00:02:00:00:00:00:00:08 102.102.102.102
03-0a-0c:01:00:02:00:00:00:00:00:09 102.102.102.102
03-0a-0c:01:00:02:00:00:00:00:00:0a 102.102.102.102



Entry is a class in which getter and setter functions used.

Ian Collins

unread,
Nov 23, 2014, 1:39:37 PM11/23/14
to
Please wrap your lines!

Why don't you use std::remove_if?

--
Ian Collins

Juha Nieminen

unread,
Nov 24, 2014, 5:02:26 AM11/24/14
to
K' Dash <adnanr...@gmail.com> wrote:
> for (std::vector<Entry>::iteratori=m_listentry.begin();i!=m_listentry.end ();i++)
> if (GUIDaddress== entry.GetGUIDaddress( ))

You aren't using the iterator for anything there. How can it match
anything inside the vector?

--- news://freenews.netfront.net/ - complaints: ne...@netfront.net ---

K' Dash

unread,
Nov 24, 2014, 4:41:57 PM11/24/14
to
thanx Juha Nieminen.
you are right. poor programming skills I have.
0 new messages