473,395 Members | 1,941 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,395 software developers and data experts.

Erasing From a map

If I have a map<double,double>, how do I delete the item whose
"second" value is X ?

Mar 28 '07 #1
4 1367
Ev********@googlemail.com wrote:
If I have a map<double,double>, how do I delete the item whose
"second" value is X ?
The same way you'd delete any item from a map-- call erase on either the
key of or an iterator to the item. I suspect that what you mean to ask
is how to _find_ an item by its second value. The simple answer is that
there's no especially good way to do this with std::map short of
iterating through the entire map. If that's not good enough then you'll
need a better data structure.
Mar 28 '07 #2
Mark P 写道:
Ev********@googlemail.com wrote:
>If I have a map<double,double>, how do I delete the item whose
"second" value is X ?

The same way you'd delete any item from a map-- call erase on either the
key of or an iterator to the item. I suspect that what you mean to ask
is how to _find_ an item by its second value. The simple answer is that
there's no especially good way to do this with std::map short of
iterating through the entire map. If that's not good enough then you'll
need a better data structure.
Can the boost library do this work?

--
Thank you very much! :)
Thank this newsgroup very much! :)
fc*****@163.com

Mar 29 '07 #3
<Ev********@googlemail.comwrote in message
news:11*********************@b75g2000hsg.googlegro ups.com...
If I have a map<double,double>, how do I delete the item whose
"second" value is X ?
I've always wanted a map with more than one index, but it's not in the
standard. So, with a standard map: iterate though the members til you find
the one with the second value of x, delete it. There may be an algorithm to
find it easier, but I don't generally use standard algorithms so can't tell
you. I would suspect if it existed it would have "find" somewhere in it.
Mar 29 '07 #4
fcvcnet wrote:
Mark P 写道:
>short of iterating through the entire map. If that's not good enough
then you'll need a better data structure.

Can the boost library do this work?
Yup. Look at multi_index.
lg,
Michael
Mar 29 '07 #5

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

Similar topics

5
by: Owen Brydon | last post by:
Hi, Is the following code legal? g++ 3.2 barfs on it, although it seems fine to me. #include <map> using std::map; int main()
5
by: Eric | last post by:
Is it possible? I'm trying to add to the current page -- but add at a specific point. Can add HTML tags from javascript midway through the page (at a place I specify) without erasing the existing...
8
by: Generic Usenet Account | last post by:
To settle the dispute regarding what happens when an "erase" method is invoked on an STL container (i.e. whether the element is merely removed from the container or whether it also gets deleted in...
12
by: Tescobar | last post by:
Over one year ago somebody asked here: how to remove selected elements from list in a loop?. The answer was as follows: for( it = l.begin(); it != l.end; ) { if(...) it = l.erase(it); else...
2
by: Rachel | last post by:
Hi All: I am having a problem with visual studio automatically erasing my code. I thought it was a fluke at first, but it KEEPS HAPPENING. I have a string variable for a data connection that I...
5
by: Alan Howard | last post by:
We're getting "ERROR (0x8007000E) Not enough storage is available to complete this operation" errors on a fairly large, busy ASP/SQL Server web site. The error is being thrown on a line calling...
11
by: eeykay | last post by:
Hello, I am facing a starnge problem while erasing the last member in a vector. I am using VC++ .NET 2002 complier. I have vector of CComPtr<..> (irrelevant here), and then I iterate over the...
5
by: ma740988 | last post by:
For starters, Happy New Year to all!! I created a vector of pairs where pair first is a primitive and pair second is a vector of ints. So now: # include <iostream> # include <vector>
0
by: masterjuan | last post by:
Networks Hacking (hack C:/ drives, severs...)and security holes all on my website & hacking commands and I explain ways of erasing your tracks so you dont get caught doing "bad" things... What do...
4
by: BibI | last post by:
Hi there, I just started programming with PERL and am trying to put together my first little data manipulation program. I am working on a MAC with OSX. I have a data file with the following...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
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 projectplanning, coding, testing,...

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.